Mehak-Mazhar commited on
Commit
03fe659
Β·
verified Β·
1 Parent(s): d800aa1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -30
app.py CHANGED
@@ -1,40 +1,53 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load Question Answering Pipelines
5
- qa_models = {
6
- "πŸ€– DistilBERT (SQuAD)": pipeline("question-answering", model="distilbert-base-uncased-distilled-squad"),
7
- "🌱 TinyRoBERTa (SQuAD2)": pipeline("question-answering", model="deepset/tinyroberta-squad2"),
8
- "πŸ“˜ BERT Base (SQuAD)": pipeline("question-answering", model="bert-base-uncased", tokenizer="bert-base-uncased")
9
- }
10
-
11
- # Inference Function
12
- def answer_question(question, context, model_name):
13
- model = qa_models[model_name]
14
- result = model(question=question, context=context)
15
- return result["answer"]
16
-
17
- # Gradio UI
18
  with gr.Blocks() as demo:
19
- gr.Markdown("<h1 style='text-align: center; color: darkorange; font-weight: bold;'>Question Answering with Lightweight LLMs</h1>")
20
- gr.Markdown("<div style='text-align: center;'>Ask questions based on the provided context using free LLMs.</div>")
21
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  with gr.Row():
23
  with gr.Column():
24
- context = gr.Textbox(label="πŸ“„ Context", lines=6, placeholder="Paste your paragraph here...")
25
- question = gr.Textbox(label="❓ Question", placeholder="Type your question here...")
26
- model_choice = gr.Radio(
27
- ["πŸ€– DistilBERT (SQuAD)", "🌱 TinyRoBERTa (SQuAD2)", "πŸ“˜ BERT Base (SQuAD)"],
28
- label="Select a Model"
29
- )
30
- submit = gr.Button("Get Answer")
31
 
32
  with gr.Column():
33
- answer = gr.Textbox(label="βœ… Answer", lines=2)
 
 
34
 
35
- submit.click(fn=answer_question, inputs=[question, context, model_choice], outputs=answer)
36
-
37
- gr.Markdown("<div style='text-align: center; color: darkorange;'>Designed by Mehak Mazhar</div>")
38
 
39
- # Set background color via CSS
40
- demo.launch(css="body { background-color: #FFF3E0; }")
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load QA pipelines (lightweight, free models)
5
+ qa_model_1 = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
6
+ qa_model_2 = pipeline("question-answering", model="deepset/tinyroberta-squad2")
7
+ qa_model_3 = pipeline("question-answering", model="bert-base-uncased")
8
+
9
+ def answer_question(question, context, model_choice):
10
+ if model_choice == "πŸ€– DistilBERT":
11
+ return qa_model_1(question=question, context=context)["answer"]
12
+ elif model_choice == "🧠 TinyRoBERTa":
13
+ return qa_model_2(question=question, context=context)["answer"]
14
+ elif model_choice == "πŸ“š BERT Base":
15
+ return qa_model_3(question=question, context=context)["answer"]
16
+
 
17
  with gr.Blocks() as demo:
18
+ # Inject light orange background and dark orange bold heading via HTML
19
+ gr.HTML("""
20
+ <style>
21
+ body {
22
+ background-color: #FFF3E0; /* light orange */
23
+ }
24
+ h1 {
25
+ color: #E65100; /* dark orange */
26
+ font-weight: bold;
27
+ text-align: center;
28
+ }
29
+ footer {
30
+ text-align: center;
31
+ margin-top: 20px;
32
+ font-weight: bold;
33
+ color: #5D4037;
34
+ }
35
+ </style>
36
+ <h1>Question Answering with Lightweight LLMs</h1>
37
+ """)
38
+
39
  with gr.Row():
40
  with gr.Column():
41
+ question = gr.Textbox(label="Enter your question")
42
+ context = gr.Textbox(label="Enter context or passage", lines=6)
43
+ model_choice = gr.Radio(["πŸ€– DistilBERT", "🧠 TinyRoBERTa", "πŸ“š BERT Base"], label="Choose a model")
44
+ button = gr.Button("Get Answer")
 
 
 
45
 
46
  with gr.Column():
47
+ output = gr.Textbox(label="Answer", lines=3)
48
+
49
+ button.click(fn=answer_question, inputs=[question, context, model_choice], outputs=output)
50
 
51
+ gr.HTML("<footer>Designed by Mehak Mazhar</footer>")
 
 
52
 
53
+ demo.launch()