Spaces:
Sleeping
Sleeping
File size: 1,985 Bytes
4594dd2 41c4b04 03fe659 41c4b04 03fe659 41c4b04 03fe659 41c4b04 03fe659 41c4b04 03fe659 41c4b04 03fe659 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
from transformers import pipeline
# Load QA pipelines (lightweight, free models)
qa_model_1 = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
qa_model_2 = pipeline("question-answering", model="deepset/tinyroberta-squad2")
qa_model_3 = pipeline("question-answering", model="bert-base-uncased")
def answer_question(question, context, model_choice):
if model_choice == "π€ DistilBERT":
return qa_model_1(question=question, context=context)["answer"]
elif model_choice == "π§ TinyRoBERTa":
return qa_model_2(question=question, context=context)["answer"]
elif model_choice == "π BERT Base":
return qa_model_3(question=question, context=context)["answer"]
with gr.Blocks() as demo:
# Inject light orange background and dark orange bold heading via HTML
gr.HTML("""
<style>
body {
background-color: #FFF3E0; /* light orange */
}
h1 {
color: #E65100; /* dark orange */
font-weight: bold;
text-align: center;
}
footer {
text-align: center;
margin-top: 20px;
font-weight: bold;
color: #5D4037;
}
</style>
<h1>Question Answering with Lightweight LLMs</h1>
""")
with gr.Row():
with gr.Column():
question = gr.Textbox(label="Enter your question")
context = gr.Textbox(label="Enter context or passage", lines=6)
model_choice = gr.Radio(["π€ DistilBERT", "π§ TinyRoBERTa", "π BERT Base"], label="Choose a model")
button = gr.Button("Get Answer")
with gr.Column():
output = gr.Textbox(label="Answer", lines=3)
button.click(fn=answer_question, inputs=[question, context, model_choice], outputs=output)
gr.HTML("<footer>Designed by Mehak Mazhar</footer>")
demo.launch()
|