nneka commited on
Commit
b32e172
1 Parent(s): 8da1f32

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ###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
3
+ """
4
+
5
+ #Install Libraries
6
+ !pip install gradio
7
+
8
+ #Import libraries
9
+ import gradio as gr
10
+ from transformers import pipeline
11
+
12
+ # Load the question-answering pipeline #using deepset/roberta-base-squad2 model
13
+ qa_model = pipeline("question-answering", model="deepset/roberta-base-squad2")
14
+
15
+ #Define the context #Cryptocurrency as the topic
16
+ context = """
17
+ Cryptocurrency is a digital currency secured by cryptography, existing on decentralized networks using blockchain technology.
18
+ It is not issued by any central authority, making it theoretically immune to government interference.
19
+ Blockchain is a connected set of blocks of information on an online ledger, containing verified transactions.
20
+ Cryptocurrencies like Ethereum's ether and Ripple XRP serve specific purposes on their blockchains.
21
+ The legal status of cryptocurrencies varies by country; in the US, they are considered a form of money.
22
+ Despite risks like scams and volatility, cryptocurrencies have a market capitalization of about $1.2 trillion.
23
+ They offer advantages such as easier fund transfers but also have disadvantages like criminal uses and volatile prices.
24
+ """
25
+
26
+
27
+ # List of questions #sample questions that users might ask
28
+ questions = [
29
+ "What is cryptocurrency and how is it secured?",
30
+ "Can you explain how blockchain technology is related to cryptocurrencies?",
31
+ "What are the different types of cryptocurrencies and their purposes?",
32
+ "Are cryptocurrencies legal, and how does their legal status vary by country?",
33
+ "What safety measures should I consider when investing in cryptocurrencies?",
34
+ "What are the advantages and disadvantages of investing in cryptocurrencies?",
35
+ "How can I buy cryptocurrencies, and what are the options available?",
36
+ "How does the regulatory landscape affect the use and investment in cryptocurrencies?",
37
+ "What are the risks associated with investing in cryptocurrencies, and how can I mitigate them?",
38
+ "Can you provide a summary of the key points about cryptocurrency?"
39
+ ]
40
+
41
+ # Print the questions #sample questions that users might ask
42
+ for i, question in enumerate(questions, 1):
43
+ print(f"Question {i}: {question}")
44
+
45
+ # Define a function to get the model's response
46
+ def get_response(context, question):
47
+ answer = qa_model(question=question, context=context)["answer"]
48
+ return answer
49
+
50
+ # Define the interface components
51
+ context_textbox = gr.Textbox(lines=10, label="Context")
52
+ question_textbox = gr.Textbox(label="Question")
53
+ output_label = gr.Label(label="Response: ")
54
+
55
+ interface = gr.Interface(
56
+ fn=get_response,
57
+ inputs=[context_textbox, question_textbox],
58
+ outputs=output_label,
59
+ title="Cryptocurrency QA System",
60
+ description="Ask a question about cryptocurrency.",
61
+ )
62
+
63
+ # Launch the interface
64
+ interface.launch()