Download app.py from wiwide/40bqa: direct link, hf CLI and curl.
- Browser
- Download file 735 Bytes
-
https://huggingface.co/spaces/wiwide/40bqa/resolve/main/app.py
- Command line
-
hf download hf://spaces/wiwide/40bqa/app.py
-
curl -L -o app.py https://huggingface.co/spaces/wiwide/40bqa/resolve/main/app.py
735 Bytes
| import requests | |
| from bs4 import BeautifulSoup | |
| from transformers import pipeline | |
| import gradio as gr | |
| def get_web_page(url): | |
| response = requests.get(url) | |
| soup = BeautifulSoup(response.text, 'html.parser') | |
| return soup.text | |
| def answer_question(question, context): | |
| qa_pipeline = pipeline("question-answering", model="tiiuae/falcon-40b") | |
| result = qa_pipeline({ | |
| 'context': context, | |
| 'question': question | |
| }) | |
| return result['answer'] | |
| def app(symbol, question): | |
| url = f"https://finance.yahoo.com/quote/{symbol}" | |
| context = get_web_page(url) | |
| answer = answer_question(question, context) | |
| return answer | |
| iface = gr.Interface(fn=app, inputs=["text", "text"], outputs="text") | |
| iface.launch() | |