Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,26 @@
|
|
1 |
import requests
|
2 |
from bs4 import BeautifulSoup
|
|
|
|
|
3 |
|
4 |
-
def
|
5 |
-
url = f"https://finance.yahoo.com/quote/{symbol}"
|
6 |
response = requests.get(url)
|
7 |
soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
-
def
|
17 |
-
url = f"https://finance.yahoo.com/quote/{symbol}
|
18 |
-
|
19 |
-
|
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 |
-
|
31 |
-
|
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()
|
|