Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| def qa_interface(context, question): | |
| model_checkpoint = "AirrStorm/BERT-SQUAD-QA-Finetuned" | |
| question_answerer = pipeline("question-answering", model=model_checkpoint) | |
| answer = question_answerer(question=question, context=context) | |
| return answer['answer'] | |
| # Define inputs | |
| inputs = [ | |
| gr.Textbox( | |
| lines=10, | |
| label="Context", | |
| placeholder="Enter the context where the answer can be found...", | |
| ), | |
| gr.Textbox( | |
| label="Question", | |
| placeholder="Enter a specific question based on the provided context..." | |
| ) | |
| ] | |
| # Define example inputs | |
| examples = [ | |
| [ | |
| "The Eiffel Tower is one of the most famous landmarks in Paris, France. It was constructed in 1889 and stands approximately 330 meters tall.", | |
| "When was the Eiffel Tower constructed?" | |
| ], | |
| [ | |
| "Python is a versatile programming language known for its simplicity and readability. It is widely used for web development, data analysis, artificial intelligence, and more.", | |
| "What is Python known for?" | |
| ], | |
| [ | |
| "The Great Wall of China stretches over 13,000 miles and was built to protect Chinese states from invasions. It is considered one of the greatest architectural achievements in history.", | |
| "How long is the Great Wall of China?" | |
| ], | |
| ] | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=qa_interface, | |
| inputs=inputs, | |
| outputs=gr.Textbox( | |
| label="Answer", | |
| placeholder="The model's answer will appear here." | |
| ), | |
| title="Question Answering (QA) Tool", | |
| description=( | |
| "This tool uses a Question Answering (QA) model to find and return the most relevant answer " | |
| "to a specific question based on the provided context.\n\n" | |
| "Provide a context paragraph and a related question to get started!" | |
| ), | |
| examples=examples, | |
| theme="hugging-face", # Optional theme for a polished look | |
| ) | |
| interface.launch() | |