File size: 721 Bytes
5197888
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from transformers import pipeline
import gradio as gr

# Set up the pipeline for question answering
pipe = pipeline("question-answering", model="Intel/dynamic_tinybert")

def answer_question(context, question):
    # Use the pipeline to get the answer
    result = pipe(question=question, context=context)
    return f'<span style="color:red">{result["answer"]}</span>'  # Wrap the answer in HTML span tag with red colour

# Create the Gradio interface
iface = gr.Interface(
    fn=answer_question,
    inputs=[
        gr.Textbox(label="Please type or copy and paste the Context"),
        gr.Textbox(label="Question")
    ],
    outputs=gr.HTML(label="Answer")  # Set output as HTML
)

# Launch the app
iface.launch()