Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize the text generation pipeline using the google/flan-t5-base model
|
| 5 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 6 |
+
|
| 7 |
+
# Define a function to generate text using the Flan-T5 model
|
| 8 |
+
def generate_text(input_text):
|
| 9 |
+
response = pipe(input_text)
|
| 10 |
+
return response[0]['generated_text']
|
| 11 |
+
|
| 12 |
+
# Set up the Gradio interface
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=generate_text, # The function to generate text
|
| 15 |
+
inputs="text", # Input type is a text field
|
| 16 |
+
outputs="text", # Output is displayed as text
|
| 17 |
+
title="Flan-T5 Text Generation", # Title of the interface
|
| 18 |
+
description="Enter text to generate a response using the google/flan-t5-base model." # Description
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the Gradio interface
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
iface.launch(share=True)
|