Spaces:
Sleeping
Sleeping
Create app.py
#1
by
kimappl
- opened
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load model
|
5 |
+
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
6 |
+
|
7 |
+
# Function to generate answers
|
8 |
+
def answer_question(context, question):
|
9 |
+
if not context or not question:
|
10 |
+
return "⚠️ Please enter both a text passage and a question!"
|
11 |
+
result = qa_pipeline(question=question, context=context)
|
12 |
+
return result["answer"]
|
13 |
+
|
14 |
+
# Create Gradio UI
|
15 |
+
gr.Interface(
|
16 |
+
fn=answer_question,
|
17 |
+
inputs=[gr.Textbox(lines=7, placeholder="Enter your text passage here..."), gr.Textbox(placeholder="Ask a question based on the text...")],
|
18 |
+
outputs="text",
|
19 |
+
title="🤔 AI Q&A Assistant",
|
20 |
+
description="Enter a passage and ask a question about it. The AI will find the best answer for you!",
|
21 |
+
allow_flagging="never"
|
22 |
+
).launch()
|