Skip to content

Commit

Permalink
add stable-diffusion conversation example
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgzn committed Sep 18, 2024
1 parent 992695d commit 8bf55e9
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/conversation_with_stablediffusion_model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Launching Web UI with arguments: --api
# Conversation with Stable-diffusion model

This example will show how to program a multi-agent conversation in AgentScope.
Complete code is in `conversation.py`, which set up a user agent and an
assistant agent to have a conversation. When user input "exit", the
conversation ends.
You can modify the `sys_prompt` to change the role of assistant agent.
```bash
# Note: Set your api_key in conversation.py first
python conversation.py
```

## Prerequisites

You need to satisfy the following requirements to run this example:

- Install Stable Diffusion Web UI by following the instructions at [AUTOMATIC1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui).
- Add the `--api` parameter to the startup options of the Stable Diffusion Web UI.
- Ensure that your host can successfully access `http://127.0.0.1:7860/`(default) any other specified host and port you choose.
- Install the latest version of AgentScope by
```bash
git clone https://github.com/modelscope/agentscope.git
cd agentscope
pip install -e .
```

## Running the Example
Run the example and input your questions.
```bash
python conversation_with_stablediffusion_model.py
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
"""A simple example for conversation between user and stable-diffusion agent."""
import agentscope
from agentscope.agents import DialogAgent
from agentscope.agents.user_agent import UserAgent


def main() -> None:
"""A basic conversation demo"""

agentscope.init(
model_configs=[
{
"model_type": "sd_txt2img",
"config_name": "sd",
"options": {
"sd_model_checkpoint": "xxxxxx",
"CLIP_stop_at_last_layers": 2,
}, # global settings, for detailed parameters
# please refer to yourhost:yourpost/docs#/default/get_config_sdapi_v1_options_get
"generate_args": {
"steps": 50,
"n_iter": 1,
"override_settings": {
"CLIP_stop_at_last_layers": 3,
# settings effective only for this conversation
# The parameters are consistent with the global settings.
},
},
},
],
project="txt2img-Agent Conversation",
save_api_invoke=True,
)

# Init two agents
dialog_agent = DialogAgent(
name="Assistant",
sys_prompt="high definition,dreamy", # replace by your desired image style prompts
model_config_name="sd", # replace by your model config name
)
user_agent = UserAgent()

# start the conversation between user and assistant
msg = None
while True:
msg = user_agent(msg)
if msg.content == "exit":
break
msg = dialog_agent(msg)


if __name__ == "__main__":
main()

0 comments on commit 8bf55e9

Please sign in to comment.