xtreme86 commited on
Commit
b7e17f1
·
1 Parent(s): 6574f7a
Files changed (1) hide show
  1. app.py +11 -8
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
- prompt,
11
- max_length=50, # Limit the max length of generated text
12
- num_return_sequences=1, # Generate only 1 sequence
13
- temperature=0.7, # Control randomness (lower = less random)
14
- top_k=50, # Limits the sampling pool to the top k tokens
15
- top_p=0.9 # Cumulative probability cutoff (for top-p sampling)
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")