|
|
|
"""question answering system using Gradio's lower-level API .ipynb |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1a_wTKHKjpXuSM8Gk7mzIWLD6geyxZJTG |
|
|
|
###Implement a question answering system using Gradio's lower-level API. The system features two input fields: the first for the context and the second for the user's question. The system then outputs the model's response |
|
""" |
|
|
|
|
|
!pip install gradio |
|
|
|
|
|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
qa_model = pipeline("question-answering", model="deepset/roberta-base-squad2") |
|
|
|
|
|
context = """ |
|
Cryptocurrency is a digital currency secured by cryptography, existing on decentralized networks using blockchain technology. |
|
It's not issued by any central authority, making it theoretically immune to government interference. |
|
Blockchain is a connected set of blocks of information on an online ledger, containing verified transactions. |
|
Cryptocurrencies like Ethereum's ether and Ripple's XRP serve specific purposes on their blockchains. |
|
The legal status of cryptocurrencies varies by country; in the US, they're considered a form of money. |
|
Despite risks like scams and volatility, cryptocurrencies have a market capitalization of about $1.2 trillion. |
|
They offer advantages such as easier fund transfers but also have disadvantages like criminal uses and volatile prices. |
|
""" |
|
|
|
|
|
questions = [ |
|
"What is cryptocurrency and how is it secured?", |
|
"Can you explain how blockchain technology is related to cryptocurrencies?", |
|
"What are the different types of cryptocurrencies and their purposes?", |
|
"Are cryptocurrencies legal, and how does their legal status vary by country?", |
|
"What safety measures should I consider when investing in cryptocurrencies?", |
|
"What are the advantages and disadvantages of investing in cryptocurrencies?", |
|
"How can I buy cryptocurrencies, and what are the options available?", |
|
"How does the regulatory landscape affect the use and investment in cryptocurrencies?", |
|
"What are the risks associated with investing in cryptocurrencies, and how can I mitigate them?", |
|
"Can you provide a summary of the key points about cryptocurrency?" |
|
] |
|
|
|
|
|
for i, question in enumerate(questions, 1): |
|
print(f"Question {i}: {question}") |
|
|
|
|
|
def get_response(context, question): |
|
answer = qa_model(question=question, context=context)["answer"] |
|
return answer |
|
|
|
|
|
context_textbox = gr.Textbox(lines=10, label="Context") |
|
question_textbox = gr.Textbox(label="Question") |
|
output_label = gr.Label(label="Response: ") |
|
|
|
interface = gr.Interface( |
|
fn=get_response, |
|
inputs=[context_textbox, question_textbox], |
|
outputs=output_label, |
|
title="Cryptocurrency QA System", |
|
description="Ask a question about cryptocurrency.", |
|
) |
|
|
|
|
|
interface.launch() |