File size: 3,219 Bytes
8da1f32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""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
"""

#Install Libraries
!pip install gradio

#Import libraries
import gradio as gr
from transformers import pipeline

# Load the question-answering pipeline #using deepset/roberta-base-squad2 model
qa_model = pipeline("question-answering", model="deepset/roberta-base-squad2")

#Define the context #Cryptocurrency as the topic
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.
"""

# List of questions  #sample questions that users might ask
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?"
]

# Print the questions  #sample questions that users might ask
for i, question in enumerate(questions, 1):
    print(f"Question {i}: {question}")

# Define a function to get the model's response
def get_response(context, question):
    answer = qa_model(question=question, context=context)["answer"]
    return answer

# Define the interface components
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.",
)

# Launch the interface
interface.launch()