lachine commited on
Commit
c1af677
·
1 Parent(s): f3b1a53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -29
app.py CHANGED
@@ -1,35 +1,17 @@
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(type="pil", 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()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ text_generator = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
 
 
 
5
 
6
+ def generate_text(prompt, quality):
7
+ length_dict = {"Low": 25, "Medium (Default)": 50, "High": 100}
8
+ length = length_dict[quality]
9
+ return text_generator(prompt, max_length=length, do_sample=True)[0]['generated_text']
10
 
11
+ iface = gr.Interface(
12
+ fn=generate_text,
13
+ inputs=["textbox", gr.inputs.Dropdown(["Low", "Medium (Default)", "High"], label="Quality")],
14
+ outputs=gr.outputs.Image(label="Generated image:")
15
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  iface.launch()