Spaces:
Runtime error
Runtime error
Download app.py from Babyloncoder/Questions-and-Answers-from-Context: direct link, hf CLI and curl.
- Browser
- Download file 721 Bytes
-
https://huggingface.co/spaces/Babyloncoder/Questions-and-Answers-from-Context/resolve/main/app.py
- Command line
-
hf download hf://spaces/Babyloncoder/Questions-and-Answers-from-Context/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Babyloncoder/Questions-and-Answers-from-Context/resolve/main/app.py
721 Bytes
| 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() | |