Spaces:
Running
Running
Upload tool
Browse files- app.py +4 -0
- requirements.txt +2 -0
- tool.py +16 -0
- tool_config.json +7 -0
app.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import launch_gradio_demo
|
2 |
+
from tool import TextToImageTool
|
3 |
+
|
4 |
+
launch_gradio_demo(TextToImageTool)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
huggingface_hub
|
tool.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers.agents.tools import Tool
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
|
5 |
+
class TextToImageTool(Tool):
|
6 |
+
default_checkpoint = "runwayml/stable-diffusion-v1-5"
|
7 |
+
description = "This is a tool that creates an image according to a prompt, which is a text description."
|
8 |
+
name = "image_generator"
|
9 |
+
inputs = {"prompt": {"type": "text", "description": "the image description"}}
|
10 |
+
output_type = "image"
|
11 |
+
model_sdxl = "stabilityai/stable-diffusion-xl-base-1.0"
|
12 |
+
client = InferenceClient(model_sdxl)
|
13 |
+
|
14 |
+
|
15 |
+
def forward(self, prompt):
|
16 |
+
return self.client.text_to_image(prompt)
|
tool_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"description": "This is a tool that creates an image according to a prompt, which is a text description.",
|
3 |
+
"inputs": "{'prompt': {'type': 'text', 'description': 'the image description'}}",
|
4 |
+
"name": "image_generator",
|
5 |
+
"output_type": "image",
|
6 |
+
"tool_class": "tool.TextToImageTool"
|
7 |
+
}
|