-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add stable-diffusion conversation example
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
examples/conversation_with_stablediffusion_model/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
54 changes: 54 additions & 0 deletions
54
examples/conversation_with_stablediffusion_model/conversation_with_stablediffusion_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |