Ram7379 commited on
Commit
30b2a3f
·
verified ·
1 Parent(s): 3ba11dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -1,18 +1,18 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load QA model
5
- qa = pipeline(
6
  "question-answering",
7
- model="deepset/roberta-base-squad2"
8
  )
9
 
10
  # Function
11
- def answer_question(context, question):
12
- if not context.strip() or not question.strip():
13
- return "Please enter both context and question."
14
 
15
- result = qa(
16
  question=question,
17
  context=context
18
  )
@@ -21,22 +21,14 @@ def answer_question(context, question):
21
 
22
  # UI
23
  demo = gr.Interface(
24
- fn=answer_question,
25
  inputs=[
26
- gr.Textbox(
27
- lines=8,
28
- label="Context",
29
- placeholder="Paste paragraph here..."
30
- ),
31
- gr.Textbox(
32
- lines=2,
33
- label="Question",
34
- placeholder="Ask question..."
35
- )
36
  ],
37
- outputs=gr.Textbox(label="Answer"),
38
- title="🔍 Question Answering System",
39
- description="Context-based QA using RoBERTa model.",
40
  theme=gr.themes.Soft()
41
  )
42
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load lightweight QA model
5
+ qa_pipeline = pipeline(
6
  "question-answering",
7
+ model="distilbert-base-cased-distilled-squad"
8
  )
9
 
10
  # Function
11
+ def answer(context, question):
12
+ if context.strip() == "" or question.strip() == "":
13
+ return "Please enter context and question."
14
 
15
+ result = qa_pipeline(
16
  question=question,
17
  context=context
18
  )
 
21
 
22
  # UI
23
  demo = gr.Interface(
24
+ fn=answer,
25
  inputs=[
26
+ gr.Textbox(lines=8, label="Context"),
27
+ gr.Textbox(lines=2, label="Question")
 
 
 
 
 
 
 
 
28
  ],
29
+ outputs="text",
30
+ title="🔍 QA System",
31
+ description="Ask questions from given context.",
32
  theme=gr.themes.Soft()
33
  )
34