lachine's picture
Update app.py
f3b1a53
raw
history blame
1.35 kB
import gradio as gr
from PIL import Image, ImageDraw, ImageFont
def generate_text(prompt, quality="Medium"):
# Your text generation code here, using the prompt and quality level inputs
# For this example, we'll just return the input prompt and quality level
return f"Prompt: {prompt}, Quality: {quality}"
def generate_image(text):
# Create a new image with a white background
img = Image.new('RGB', (500, 500), color='white')
# Draw the text onto the image
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("arial.ttf", size=20)
draw.text((10, 10), text, fill='black', font=font)
# Return the image as a numpy array
return img
prompt_input = gr.inputs.Textbox(label="Enter your prompt:")
quality_dropdown = gr.inputs.Dropdown(choices=["Low", "Medium", "High"], label="Select quality level:", default="Medium")
output_text = gr.outputs.Textbox(label="Generated text:")
output_image = gr.outputs.Image(type="pil", label="Generated image:")
iface = gr.Interface(fn=generate_text, inputs=[prompt_input, quality_dropdown], outputs=[output_text, output_image], title="Text and Image Generator")
def update_image(output_text):
# Generate a new image based on the generated text
img = generate_image(output_text)
return img
iface.out[1].update(update_image, "output_text")
iface.launch()