File size: 1,348 Bytes
39c9612
1bd70ba
39c9612
1bd70ba
 
 
 
39c9612
1bd70ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3b1a53
1bd70ba
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()