Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
qa = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 5 |
+
|
| 6 |
+
def answer(question, context):
|
| 7 |
+
if not context.strip():
|
| 8 |
+
return "Please upload or paste content first."
|
| 9 |
+
return qa(question=question, context=context)["answer"]
|
| 10 |
+
|
| 11 |
+
with gr.Blocks() as demo:
|
| 12 |
+
gr.Markdown("## Free AI Document Chatbot")
|
| 13 |
+
|
| 14 |
+
context = gr.Textbox(label="Paste document text here", lines=10)
|
| 15 |
+
question = gr.Textbox(label="Ask a question")
|
| 16 |
+
|
| 17 |
+
output = gr.Textbox(label="Answer")
|
| 18 |
+
|
| 19 |
+
ask = gr.Button("Ask")
|
| 20 |
+
|
| 21 |
+
ask.click(answer, [question, context], output)
|
| 22 |
+
|
| 23 |
+
demo.launch()
|