Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,53 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
# Gradio UI
|
18 |
with gr.Blocks() as demo:
|
19 |
-
|
20 |
-
gr.
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
with gr.Row():
|
23 |
with gr.Column():
|
24 |
-
|
25 |
-
|
26 |
-
model_choice = gr.Radio(
|
27 |
-
|
28 |
-
label="Select a Model"
|
29 |
-
)
|
30 |
-
submit = gr.Button("Get Answer")
|
31 |
|
32 |
with gr.Column():
|
33 |
-
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
gr.Markdown("<div style='text-align: center; color: darkorange;'>Designed by Mehak Mazhar</div>")
|
38 |
|
39 |
-
|
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()
|
|