Ram7379 commited on
Commit
5fd2a0b
·
verified ·
1 Parent(s): 832827e

Create app.py

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