Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
|
4 |
-
|
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
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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()
|