Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load the text-to-text generation pipeline using the FLAN-T5 model
|
| 5 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-large")
|
| 6 |
+
|
| 7 |
+
# Function to generate text based on user input
|
| 8 |
+
def generate_text(input_text):
|
| 9 |
+
# Generate output text using the pipeline
|
| 10 |
+
generated = pipe(input_text)
|
| 11 |
+
return generated[0]['generated_text']
|
| 12 |
+
|
| 13 |
+
# Set up the Gradio interface
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
gr.Markdown("# Text Generation using FLAN-T5 (google/flan-t5-large)")
|
| 16 |
+
|
| 17 |
+
# Input for user to provide text
|
| 18 |
+
text_input = gr.Textbox(label="Enter Text Prompt", placeholder="Type your prompt here...", value="Translate English to French: 'Hello, how are you?'")
|
| 19 |
+
|
| 20 |
+
# Output to display the generated text
|
| 21 |
+
output_text = gr.Textbox(label="Generated Text", interactive=False)
|
| 22 |
+
|
| 23 |
+
# Button to trigger text generation
|
| 24 |
+
generate_button = gr.Button("Generate Text")
|
| 25 |
+
|
| 26 |
+
# Link button click to text generation function
|
| 27 |
+
generate_button.click(fn=generate_text, inputs=text_input, outputs=output_text)
|
| 28 |
+
|
| 29 |
+
# Launch the Gradio app
|
| 30 |
+
demo.launch()
|