Spaces:
Runtime error
Runtime error
AstraBert
commited on
Commit
·
bcc7abd
1
Parent(s):
55c7bc1
build commit
Browse files- README.md +5 -3
- app.py +62 -0
- generated_img.png +0 -0
- imgen.py +4 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -4,10 +4,12 @@ emoji: 🐠
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
| 10 |
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.25.0
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# awesome-tiny-sd
|
| 14 |
+
|
| 15 |
+
Tiny stable diffusion chatbot based on [segmind/small-sd](https://huggingface.co/segmind/small-sd) to generate image upon text prompts.
|
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
from imgen import *
|
| 4 |
+
|
| 5 |
+
def print_like_dislike(x: gr.LikeData):
|
| 6 |
+
print(x.index, x.value, x.liked)
|
| 7 |
+
|
| 8 |
+
def add_message(history, message):
|
| 9 |
+
if len(message["files"]) > 0:
|
| 10 |
+
history.append((message["files"], None))
|
| 11 |
+
if message["text"] is not None and message["text"] != "":
|
| 12 |
+
history.append((message["text"], None))
|
| 13 |
+
return history, gr.MultimodalTextbox(value=None, interactive=False)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def bot(history):
|
| 18 |
+
if type(history[-1][0]) != tuple:
|
| 19 |
+
try:
|
| 20 |
+
prompt = history[-1][0]
|
| 21 |
+
image = pipeline(prompt).images[0]
|
| 22 |
+
image.save("generated_image.png")
|
| 23 |
+
response = ("generated_img.png",)
|
| 24 |
+
history[-1][1] = response
|
| 25 |
+
yield history
|
| 26 |
+
except Exception as e:
|
| 27 |
+
response = f"Sorry, the error '{e}' occured while generating the response; check [troubleshooting documentation](https://astrabert.github.io/awesome-tiny-sd/#troubleshooting) for more"
|
| 28 |
+
history[-1][1] = ""
|
| 29 |
+
for character in response:
|
| 30 |
+
history[-1][1] += character
|
| 31 |
+
time.sleep(0.05)
|
| 32 |
+
yield history
|
| 33 |
+
if type(history[-1][0]) == tuple:
|
| 34 |
+
response = f"Sorry, this version still does not support uploaded files :("
|
| 35 |
+
history[-1][1] = ""
|
| 36 |
+
for character in response:
|
| 37 |
+
history[-1][1] += character
|
| 38 |
+
time.sleep(0.05)
|
| 39 |
+
yield history
|
| 40 |
+
|
| 41 |
+
with gr.Blocks() as demo:
|
| 42 |
+
chatbot = gr.Chatbot(
|
| 43 |
+
[[None, ("Hi, I am awesome-tiny-sd, a little stable diffusion model that lets you generate images:blush:\nJust write me a prompt, I'll generate what you ask for:heart:",)]],
|
| 44 |
+
label="awesome-tiny-sd",
|
| 45 |
+
elem_id="chatbot",
|
| 46 |
+
bubble_full_width=False,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
chat_input = gr.MultimodalTextbox(interactive=True, file_types=["pdf"], placeholder="Enter your image-generating prompt...", show_label=False)
|
| 50 |
+
|
| 51 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
| 52 |
+
bot_msg = chat_msg.then(bot, chatbot, chatbot, api_name="bot_response")
|
| 53 |
+
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
|
| 54 |
+
|
| 55 |
+
chatbot.like(print_like_dislike, None, None)
|
| 56 |
+
clear = gr.ClearButton(chatbot)
|
| 57 |
+
|
| 58 |
+
demo.queue()
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|
| 61 |
+
|
| 62 |
+
|
generated_img.png
ADDED
|
imgen.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import DiffusionPipeline
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
pipeline = DiffusionPipeline.from_pretrained("segmind/small-sd", torch_dtype=torch.float32)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.25.0
|
| 2 |
+
diffusers==0.27.2
|
| 3 |
+
torch==2.1.2
|