savan360 commited on
Commit
2aa3b64
·
verified ·
1 Parent(s): 93d7a55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -1,23 +1,26 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load a question-answering model instead of a text generator
5
- qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
6
 
7
- def get_answer(question):
8
- context = """
9
- London is the capital of the United Kingdom. The UK consists of England, Scotland, Wales, and Northern Ireland.
10
- """
11
- answer = qa_pipeline(question=question, context=context)
12
- return answer["answer"]
 
 
 
13
 
14
- # Create Gradio Interface
15
  iface = gr.Interface(
16
- fn=get_answer,
17
  inputs="text",
18
  outputs="text",
19
  title="Ask Any Question",
20
- description="Ask factual questions and get precise answers."
21
  )
22
 
23
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Use a different LLM (GPT-Neo instead of GPT-2)
5
+ generator = pipeline('text-generation', model='EleutherAI/gpt-neo-125M')
6
 
7
+ def generate_text(prompt):
8
+ generated = generator(
9
+ prompt,
10
+ max_length=20, # Limit response length
11
+ do_sample=False, # Make output deterministic
12
+ temperature=0.1, # Reduce randomness
13
+ repetition_penalty=2.0 # Prevent repeating words
14
+ )
15
+ return generated[0]['generated_text']
16
 
17
+ # Create the Gradio interface
18
  iface = gr.Interface(
19
+ fn=generate_text,
20
  inputs="text",
21
  outputs="text",
22
  title="Ask Any Question",
23
+ description="Ask a question and get an answer using GPT-Neo."
24
  )
25
 
26
  iface.launch()