Spaces:
Runtime error
Runtime error
Babyloncoder
commited on
Commit
•
5197888
1
Parent(s):
6ec0f28
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Set up the pipeline for question answering
|
5 |
+
pipe = pipeline("question-answering", model="Intel/dynamic_tinybert")
|
6 |
+
|
7 |
+
def answer_question(context, question):
|
8 |
+
# Use the pipeline to get the answer
|
9 |
+
result = pipe(question=question, context=context)
|
10 |
+
return f'<span style="color:red">{result["answer"]}</span>' # Wrap the answer in HTML span tag with red colour
|
11 |
+
|
12 |
+
# Create the Gradio interface
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=answer_question,
|
15 |
+
inputs=[
|
16 |
+
gr.Textbox(label="Please type or copy and paste the Context"),
|
17 |
+
gr.Textbox(label="Question")
|
18 |
+
],
|
19 |
+
outputs=gr.HTML(label="Answer") # Set output as HTML
|
20 |
+
)
|
21 |
+
|
22 |
+
# Launch the app
|
23 |
+
iface.launch()
|
24 |
+
|