app.py
CHANGED
|
@@ -4,21 +4,24 @@ from transformers import pipeline
|
|
| 4 |
# Load a text generation pipeline with Flan-T5-small model
|
| 5 |
llm_pipeline = pipeline(task="text-generation", model="google/flan-t5-small")
|
| 6 |
|
| 7 |
-
# Function to generate text based on user input
|
| 8 |
def generate_text(prompt):
|
|
|
|
|
|
|
|
|
|
| 9 |
result = llm_pipeline(
|
| 10 |
-
|
| 11 |
-
max_length=50,
|
| 12 |
-
num_return_sequences=1,
|
| 13 |
-
temperature=0.7,
|
| 14 |
-
top_k=50,
|
| 15 |
-
top_p=0.9
|
| 16 |
)
|
| 17 |
return result[0]['generated_text']
|
| 18 |
|
| 19 |
# Define the Gradio interface
|
| 20 |
with gr.Blocks() as gradio_app:
|
| 21 |
-
gr.Markdown("## Text Generation with Flan-T5-small")
|
| 22 |
prompt = gr.Textbox(label="Enter your prompt", placeholder="Type something here...")
|
| 23 |
output = gr.Textbox(label="Generated text")
|
| 24 |
submit_btn = gr.Button("Generate")
|
|
|
|
| 4 |
# Load a text generation pipeline with Flan-T5-small model
|
| 5 |
llm_pipeline = pipeline(task="text-generation", model="google/flan-t5-small")
|
| 6 |
|
| 7 |
+
# Function to generate text based on user input, with a system instruction
|
| 8 |
def generate_text(prompt):
|
| 9 |
+
system_instruction = "Respond like a helpful AI: " # System instruction
|
| 10 |
+
full_prompt = system_instruction + prompt # Combine the instruction with user input
|
| 11 |
+
|
| 12 |
result = llm_pipeline(
|
| 13 |
+
full_prompt,
|
| 14 |
+
max_length=50,
|
| 15 |
+
num_return_sequences=1,
|
| 16 |
+
temperature=0.7,
|
| 17 |
+
top_k=50,
|
| 18 |
+
top_p=0.9
|
| 19 |
)
|
| 20 |
return result[0]['generated_text']
|
| 21 |
|
| 22 |
# Define the Gradio interface
|
| 23 |
with gr.Blocks() as gradio_app:
|
| 24 |
+
gr.Markdown("## Text Generation with Flan-T5-small (Helpful AI Mode)")
|
| 25 |
prompt = gr.Textbox(label="Enter your prompt", placeholder="Type something here...")
|
| 26 |
output = gr.Textbox(label="Generated text")
|
| 27 |
submit_btn = gr.Button("Generate")
|