Spaces:
Sleeping
Sleeping
Commit
·
2f2ce5c
1
Parent(s):
cf4a11d
Created QandA AI app
Browse files- app.py +30 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Part 1: Load the model ONCE
|
| 5 |
+
print("Loading the MobileBERT model...")
|
| 6 |
+
info_extractor = pipeline("question-answering", model="csarron/mobilebert-uncased-squad-v2")
|
| 7 |
+
print("Model loaded successfully!")
|
| 8 |
+
|
| 9 |
+
# Part 2: Create the function that the UI will call
|
| 10 |
+
# This function takes the document and question from the UI,
|
| 11 |
+
# gets the answer from the model, and returns it.
|
| 12 |
+
def extract_information(context, question):
|
| 13 |
+
print(f"Extracting answer for question: '{question}'")
|
| 14 |
+
result = info_extractor(question=question, context=context)
|
| 15 |
+
return result['answer']
|
| 16 |
+
|
| 17 |
+
# Part 3: Build and launch the Gradio Interface
|
| 18 |
+
print("Launching Gradio interface...")
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=extract_information,
|
| 21 |
+
inputs=[
|
| 22 |
+
gr.Textbox(lines=7, label="Document", placeholder="Paste the document or text you want to ask questions about..."),
|
| 23 |
+
gr.Textbox(label="Question", placeholder="What specific detail are you looking for?")
|
| 24 |
+
],
|
| 25 |
+
outputs=gr.Textbox(label="Answer"),
|
| 26 |
+
title="💡 Efficient Information Extractor",
|
| 27 |
+
description="Ask a question about the document below to pull out specific details using a MobileBERT model."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|