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

Upload 2 files

Browse files
question_answering_system_using_gradio's_lower_level_api_.app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """question answering system using Gradio's lower-level API .ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1a_wTKHKjpXuSM8Gk7mzIWLD6geyxZJTG
8
+
9
+ ###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
10
+ """
11
+
12
+ #Install Libraries
13
+ !pip install gradio
14
+
15
+ #Import libraries
16
+ import gradio as gr
17
+ from transformers import pipeline
18
+
19
+ # Load the question-answering pipeline #using deepset/roberta-base-squad2 model
20
+ qa_model = pipeline("question-answering", model="deepset/roberta-base-squad2")
21
+
22
+ #Define the context #Cryptocurrency as the topic
23
+ context = """
24
+ Cryptocurrency is a digital currency secured by cryptography, existing on decentralized networks using blockchain technology.
25
+ It's not issued by any central authority, making it theoretically immune to government interference.
26
+ Blockchain is a connected set of blocks of information on an online ledger, containing verified transactions.
27
+ Cryptocurrencies like Ethereum's ether and Ripple's XRP serve specific purposes on their blockchains.
28
+ The legal status of cryptocurrencies varies by country; in the US, they're considered a form of money.
29
+ Despite risks like scams and volatility, cryptocurrencies have a market capitalization of about $1.2 trillion.
30
+ They offer advantages such as easier fund transfers but also have disadvantages like criminal uses and volatile prices.
31
+ """
32
+
33
+ # List of questions #sample questions that users might ask
34
+ questions = [
35
+ "What is cryptocurrency and how is it secured?",
36
+ "Can you explain how blockchain technology is related to cryptocurrencies?",
37
+ "What are the different types of cryptocurrencies and their purposes?",
38
+ "Are cryptocurrencies legal, and how does their legal status vary by country?",
39
+ "What safety measures should I consider when investing in cryptocurrencies?",
40
+ "What are the advantages and disadvantages of investing in cryptocurrencies?",
41
+ "How can I buy cryptocurrencies, and what are the options available?",
42
+ "How does the regulatory landscape affect the use and investment in cryptocurrencies?",
43
+ "What are the risks associated with investing in cryptocurrencies, and how can I mitigate them?",
44
+ "Can you provide a summary of the key points about cryptocurrency?"
45
+ ]
46
+
47
+ # Print the questions #sample questions that users might ask
48
+ for i, question in enumerate(questions, 1):
49
+ print(f"Question {i}: {question}")
50
+
51
+ # Define a function to get the model's response
52
+ def get_response(context, question):
53
+ answer = qa_model(question=question, context=context)["answer"]
54
+ return answer
55
+
56
+ # Define the interface components
57
+ context_textbox = gr.Textbox(lines=10, label="Context")
58
+ question_textbox = gr.Textbox(label="Question")
59
+ output_label = gr.Label(label="Response: ")
60
+
61
+ interface = gr.Interface(
62
+ fn=get_response,
63
+ inputs=[context_textbox, question_textbox],
64
+ outputs=output_label,
65
+ title="Cryptocurrency QA System",
66
+ description="Ask a question about cryptocurrency.",
67
+ )
68
+
69
+ # Launch the interface
70
+ interface.launch()
requirements.txt.rtf ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {\rtf1\ansi\ansicpg1252\cocoartf2580
2
+ \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
3
+ {\colortbl;\red255\green255\blue255;}
4
+ {\*\expandedcolortbl;;}
5
+ \margl1440\margr1440\vieww11520\viewh8400\viewkind0
6
+ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
7
+
8
+ \f0\fs24 \cf0 gradio==2.2.7\
9
+ transformers==4.13.0\
10
+ torch==1.10.1\
11
+ \
12
+ }