Add initial project files including README, workflows, app, and requirements
Browse files- .github/workflows/check-size.yml +16 -0
- .github/workflows/main.yml +20 -0
- README.md +31 -1
- app.py +100 -0
- requirements.txt +2 -0
.github/workflows/check-size.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Check file size
|
| 2 |
+
on: # or directly `on: [push]` to run the action on every push on any branch
|
| 3 |
+
pull_request:
|
| 4 |
+
branches: [new]
|
| 5 |
+
|
| 6 |
+
# to run this workflow manually from the Actions tab
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
sync-to-hub:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- name: Check large files
|
| 14 |
+
uses: ActionsDesk/[email protected]
|
| 15 |
+
with:
|
| 16 |
+
filesizelimit: 10485760 # this is 10MB so we can sync to HF Spaces
|
.github/workflows/main.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to Hugging Face hub
|
| 2 |
+
on:
|
| 3 |
+
push:
|
| 4 |
+
branches: [main]
|
| 5 |
+
|
| 6 |
+
# to run this workflow manually from the Actions tab
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
sync-to-hub:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v3
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
# lfs: true
|
| 17 |
+
- name: Push to hub
|
| 18 |
+
env:
|
| 19 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 20 |
+
run: git push https://OxbridegeEcon:[email protected]/spaces/Oxbridge-Economics/watchpit-st main --force
|
README.md
CHANGED
|
@@ -1 +1,31 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: watchpit - prototype
|
| 3 |
+
emoji: 🔥
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.42.0 # The latest supported version
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
Check out the configuration reference at <https://huggingface.co/docs/hub/spaces-config-reference>
|
| 12 |
+
|
| 13 |
+
# 🎈 Blank app template
|
| 14 |
+
|
| 15 |
+
A simple Streamlit app template for you to modify!
|
| 16 |
+
|
| 17 |
+
[](https://blank-app-template.streamlit.app/)
|
| 18 |
+
|
| 19 |
+
### How to run it on your own machine
|
| 20 |
+
|
| 21 |
+
1. Install the requirements
|
| 22 |
+
|
| 23 |
+
```
|
| 24 |
+
$ pip install -r requirements.txt
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
2. Run the app
|
| 28 |
+
|
| 29 |
+
```
|
| 30 |
+
$ streamlit run app.py
|
| 31 |
+
```
|
app.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Streamlit app example."""
|
| 2 |
+
import os
|
| 3 |
+
import uuid
|
| 4 |
+
import json
|
| 5 |
+
import requests
|
| 6 |
+
import streamlit as st
|
| 7 |
+
|
| 8 |
+
DOMAIN = "https://oxbridge-economics-watchpit.hf.space"
|
| 9 |
+
HEADERS = {
|
| 10 |
+
'Content-Type': 'application/json',
|
| 11 |
+
'Authorization': f'Bearer {os.environ.get("HF_TOKEN")}'
|
| 12 |
+
}
|
| 13 |
+
# STOCK = ["AAPL","ADBE","AMD","AMZN","ARM","ASML","AVGO","BRK.B","BTC","CHAU","COIN","CVNA",
|
| 14 |
+
# "DXYZ","GBTC","GOOG","GOOGL","KULR","MARA","META","MRVL","MSFT","MSTR","NBIS",
|
| 15 |
+
# "NFLX","NVDA","PDD","PLTR","QCOM","QQQ","QUBT","RDDT","ROKU","RR","SPY","TEM","TSLA"]
|
| 16 |
+
|
| 17 |
+
if 'chat_id' not in st.session_state:
|
| 18 |
+
st.session_state.chat_id = str(uuid.uuid4())
|
| 19 |
+
st.session_state.user_id = str(uuid.uuid4())
|
| 20 |
+
|
| 21 |
+
# with st.sidebar:
|
| 22 |
+
# st.header("Symbols Selection")
|
| 23 |
+
# symbols = st.multiselect("Select stocks", STOCK, default=["AAPL"])
|
| 24 |
+
# mode = st.selectbox("Mode", ["research", "stream"])
|
| 25 |
+
# retrivers = st.multiselect("Retrievers", ["duckduckgo", "google"], default=["duckduckgo"])
|
| 26 |
+
|
| 27 |
+
# def get_research(query):
|
| 28 |
+
# """
|
| 29 |
+
# Sends a POST request to the research endpoint with the given query.
|
| 30 |
+
|
| 31 |
+
# Args:
|
| 32 |
+
# query (str): The search query to be sent in the request payload.
|
| 33 |
+
|
| 34 |
+
# Returns:
|
| 35 |
+
# str: The response text from the research endpoint.
|
| 36 |
+
|
| 37 |
+
# Raises:
|
| 38 |
+
# requests.exceptions.RequestException: If there is an issue with the request.
|
| 39 |
+
# """
|
| 40 |
+
# payload = json.dumps({
|
| 41 |
+
# "query": query,
|
| 42 |
+
# "symbols": symbols,
|
| 43 |
+
# "headers": {
|
| 44 |
+
# "retrievers": ",".join(retrivers)
|
| 45 |
+
# }
|
| 46 |
+
# })
|
| 47 |
+
# response = requests.request(
|
| 48 |
+
# "POST", f"{DOMAIN}/research", headers=HEADERS, data=payload, timeout=100)
|
| 49 |
+
# response = response.json()
|
| 50 |
+
# print(response["report"])
|
| 51 |
+
# return response["report"]
|
| 52 |
+
|
| 53 |
+
def get_answer(query):
|
| 54 |
+
"""
|
| 55 |
+
Sends a query to a specified URL and retrieves the answer from the response.
|
| 56 |
+
|
| 57 |
+
Args:
|
| 58 |
+
query (str): The query string to be sent.
|
| 59 |
+
symbols (list): The symbols to be sent
|
| 60 |
+
|
| 61 |
+
Returns:
|
| 62 |
+
str: The answer extracted from the response.
|
| 63 |
+
"""
|
| 64 |
+
payload = json.dumps({
|
| 65 |
+
"query": query,
|
| 66 |
+
"chat_id": st.session_state.chat_id,
|
| 67 |
+
"user_id": st.session_state.user_id,
|
| 68 |
+
})
|
| 69 |
+
contexts = []
|
| 70 |
+
response_answer = ""
|
| 71 |
+
api_response = requests.request(
|
| 72 |
+
"POST", f"{DOMAIN}/stream", headers=HEADERS,data=payload, stream=True, timeout=60)
|
| 73 |
+
for response_str in api_response.text.strip().split('\n\n'):
|
| 74 |
+
response_list = response_str.split('\n')
|
| 75 |
+
response_str = response_list[1]
|
| 76 |
+
json_object = json.loads(response_str.replace("data: ", ""))
|
| 77 |
+
if "answer" in json_object:
|
| 78 |
+
response_answer = response_answer + json_object['answer']
|
| 79 |
+
elif "context" in json_object:
|
| 80 |
+
contexts.append(json_object['context'])
|
| 81 |
+
# elif "questions" in json_object:
|
| 82 |
+
# questions = json_object['questions']
|
| 83 |
+
return response_answer
|
| 84 |
+
|
| 85 |
+
if "messages" not in st.session_state:
|
| 86 |
+
st.session_state.messages = []
|
| 87 |
+
|
| 88 |
+
for message in st.session_state.messages:
|
| 89 |
+
with st.chat_message(message["role"]):
|
| 90 |
+
st.markdown(message["content"])
|
| 91 |
+
|
| 92 |
+
if prompt := st.chat_input("What is up?"):
|
| 93 |
+
|
| 94 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 95 |
+
with st.chat_message("user"):
|
| 96 |
+
st.markdown(prompt)
|
| 97 |
+
answer = get_answer(prompt)
|
| 98 |
+
with st.chat_message("assistant"):
|
| 99 |
+
response_content = st.markdown(answer)
|
| 100 |
+
st.session_state.messages.append({"role": "assistant", "content": answer})
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
requests
|