wiwide commited on
Commit
c633bb4
1 Parent(s): cb0339f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -1,32 +1,26 @@
1
  import requests
2
  from bs4 import BeautifulSoup
 
 
3
 
4
- def get_stock_data(symbol):
5
- url = f"https://finance.yahoo.com/quote/{symbol}"
6
  response = requests.get(url)
7
  soup = BeautifulSoup(response.text, 'html.parser')
 
8
 
9
- data = {}
10
- data['symbol'] = symbol
11
- data['price'] = soup.find_all('div', {'class': 'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find('span').text
12
- data['change'] = soup.find_all('div', {'class': 'My(6px) Pos(r) smartphone_Mt(6px)'})[0].find_all('span')[1].text
13
-
14
- return data
 
15
 
16
- def get_news(symbol):
17
- url = f"https://finance.yahoo.com/quote/{symbol}/news?p={symbol}"
18
- response = requests.get(url)
19
- soup = BeautifulSoup(response.text, 'html.parser')
20
-
21
- news = []
22
- for item in soup.find_all('h3', {'class': 'Mb(5px)'}):
23
- news_item = {}
24
- news_item['title'] = item.text
25
- news_item['link'] = item.find('a')['href']
26
- news.append(news_item)
27
-
28
- return news
29
 
30
- symbol = input("Please enter a stock symbol: ")
31
- print(get_stock_data(symbol))
32
- print(get_news(symbol))
 
1
  import requests
2
  from bs4 import BeautifulSoup
3
+ from transformers import pipeline
4
+ import gradio as gr
5
 
6
+ def get_web_page(url):
 
7
  response = requests.get(url)
8
  soup = BeautifulSoup(response.text, 'html.parser')
9
+ return soup.text
10
 
11
+ def answer_question(question, context):
12
+ qa_pipeline = pipeline("question-answering", model="tiiuae/falcon-40b")
13
+ result = qa_pipeline({
14
+ 'context': context,
15
+ 'question': question
16
+ })
17
+ return result['answer']
18
 
19
+ def app(symbol, question):
20
+ url = f"https://finance.yahoo.com/quote/{symbol}"
21
+ context = get_web_page(url)
22
+ answer = answer_question(question, context)
23
+ return answer
 
 
 
 
 
 
 
 
24
 
25
+ iface = gr.Interface(fn=app, inputs=["text", "text"], outputs="text")
26
+ iface.launch()