Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,35 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 3 |
|
| 4 |
+
def generate_text(prompt, quality="Medium"):
|
| 5 |
+
# Your text generation code here, using the prompt and quality level inputs
|
| 6 |
+
# For this example, we'll just return the input prompt and quality level
|
| 7 |
+
return f"Prompt: {prompt}, Quality: {quality}"
|
| 8 |
|
| 9 |
+
def generate_image(text):
|
| 10 |
+
# Create a new image with a white background
|
| 11 |
+
img = Image.new('RGB', (500, 500), color='white')
|
| 12 |
+
|
| 13 |
+
# Draw the text onto the image
|
| 14 |
+
draw = ImageDraw.Draw(img)
|
| 15 |
+
font = ImageFont.truetype("arial.ttf", size=20)
|
| 16 |
+
draw.text((10, 10), text, fill='black', font=font)
|
| 17 |
+
|
| 18 |
+
# Return the image as a numpy array
|
| 19 |
+
return img
|
| 20 |
+
|
| 21 |
+
prompt_input = gr.inputs.Textbox(label="Enter your prompt:")
|
| 22 |
+
quality_dropdown = gr.inputs.Dropdown(choices=["Low", "Medium", "High"], label="Select quality level:", default="Medium")
|
| 23 |
+
output_text = gr.outputs.Textbox(label="Generated text:")
|
| 24 |
+
output_image = gr.outputs.Image(label="Generated image:")
|
| 25 |
+
|
| 26 |
+
iface = gr.Interface(fn=generate_text, inputs=[prompt_input, quality_dropdown], outputs=[output_text, output_image], title="Text and Image Generator")
|
| 27 |
+
|
| 28 |
+
def update_image(output_text):
|
| 29 |
+
# Generate a new image based on the generated text
|
| 30 |
+
img = generate_image(output_text)
|
| 31 |
+
return img
|
| 32 |
+
|
| 33 |
+
iface.out[1].update(update_image, "output_text")
|
| 34 |
+
|
| 35 |
+
iface.launch()
|