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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -1,26 +1,24 @@
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()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load a Question Answering model
5
+ qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
6
 
7
+ def get_answer(question):
8
+ # Define a context for factual answers
9
+ context = """
10
+ New Delhi is the capital of India. India is a country in South Asia and is the seventh-largest country by land area.
11
+ """
12
+ answer = qa_pipeline(question=question, context=context)
13
+ return answer["answer"]
 
 
14
 
15
+ # Create Gradio Interface
16
  iface = gr.Interface(
17
+ fn=get_answer,
18
  inputs="text",
19
  outputs="text",
20
  title="Ask Any Question",
21
+ description="Ask factual questions and get precise answers."
22
  )
23
 
24
  iface.launch()