Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the pipeline for text2text-generation using the Blenderbot model
|
| 5 |
+
chatbot = pipeline(task="text2text-generation", model="facebook/blenderbot-400M-distill")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Define the text generation function
|
| 9 |
+
def generate_text(prompt, max_length=50):
|
| 10 |
+
response = pipe(prompt, max_length=max_length, truncation=True)
|
| 11 |
+
return response[0]['generated_text']
|
| 12 |
+
|
| 13 |
+
# Create the Gradio app interface
|
| 14 |
+
with gr.Blocks() as app:
|
| 15 |
+
gr.Markdown("## Text-to-Text Generation App")
|
| 16 |
+
gr.Markdown(
|
| 17 |
+
"Enter a prompt below and the model will generate text. "
|
| 18 |
+
"This app uses the `facebook/blenderbot-400M-distill` model."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
with gr.Row():
|
| 22 |
+
input_prompt = gr.Textbox(label="Input Prompt", placeholder="Type your prompt here...")
|
| 23 |
+
output_text = gr.Textbox(label="Generated Text")
|
| 24 |
+
|
| 25 |
+
max_length = gr.Slider(label="Max Length", minimum=10, maximum=200, step=10, value=50)
|
| 26 |
+
|
| 27 |
+
submit_button = gr.Button("Generate")
|
| 28 |
+
|
| 29 |
+
submit_button.click(
|
| 30 |
+
fn=generate_text,
|
| 31 |
+
inputs=[input_prompt, max_length],
|
| 32 |
+
outputs=output_text
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Launch the app
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
app.launch()
|