Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files- Dockerfile +20 -0
- app.py +57 -0
- requirements.txt +3 -0
- workcell.yaml +10 -0
Dockerfile
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.8
|
5 |
+
|
6 |
+
# Set up a new user named "user" with user ID 1000
|
7 |
+
RUN useradd -m -u 1000 user
|
8 |
+
# Switch to the "user" user
|
9 |
+
USER user
|
10 |
+
# Set home to the user's home directory
|
11 |
+
ENV HOME=/home/user \
|
12 |
+
PATH=/home/user/.local/bin:$PATH
|
13 |
+
# Set the working directory to the user's home directory
|
14 |
+
WORKDIR $HOME/app
|
15 |
+
|
16 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
17 |
+
COPY --chown=user . $HOME/app
|
18 |
+
RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt
|
19 |
+
|
20 |
+
CMD ["workcell", "serve", "--config", "workcell.yaml", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datetime
|
2 |
+
from pydantic import BaseModel, Field
|
3 |
+
from typing import Dict, List, Optional
|
4 |
+
import yfinance as yf
|
5 |
+
import plotly.express as px
|
6 |
+
from workcell.integrations.types import PlotlyPlot
|
7 |
+
|
8 |
+
|
9 |
+
class Input(BaseModel):
|
10 |
+
tickers: List[str] = Field(
|
11 |
+
default=['AAPL','AMZN','META'], max_items=10, description="List of ticker values"
|
12 |
+
)
|
13 |
+
|
14 |
+
|
15 |
+
def load_data(tickers):
|
16 |
+
"""Download ticker price data from ticker list.
|
17 |
+
e.g. tickers = ['AAPL','AMZN','GOOG']
|
18 |
+
"""
|
19 |
+
start = datetime.datetime(2022, 1, 1)
|
20 |
+
end = datetime.datetime.now() # latest
|
21 |
+
data = yf.download(tickers, start=start, end=end, interval='1d')
|
22 |
+
# adjust close
|
23 |
+
close = data['Adj Close']
|
24 |
+
return close
|
25 |
+
|
26 |
+
|
27 |
+
def visualization(df):
|
28 |
+
"""Visualization price plot by yfinance dataframe.
|
29 |
+
e.g. df = yf.download(***)
|
30 |
+
"""
|
31 |
+
template = 'plotly_white'
|
32 |
+
fig = px.line(df, x=df.index, y=df.columns.tolist(), template=template)
|
33 |
+
fig.update_xaxes(
|
34 |
+
rangeslider_visible=True,
|
35 |
+
rangeselector=dict(
|
36 |
+
buttons=list([
|
37 |
+
dict(count=1, label="1m", step="month", stepmode="backward"),
|
38 |
+
dict(count=6, label="6m", step="month", stepmode="backward"),
|
39 |
+
dict(count=1, label="YTD", step="year", stepmode="todate"),
|
40 |
+
dict(count=1, label="1y", step="year", stepmode="backward"),
|
41 |
+
dict(step="all")
|
42 |
+
])
|
43 |
+
)
|
44 |
+
)
|
45 |
+
fig.update_layout(hovermode="x")
|
46 |
+
return fig
|
47 |
+
|
48 |
+
|
49 |
+
def stock_viewer(input: Input) -> PlotlyPlot:
|
50 |
+
"""Input ticker list, returns multiple stocks price. Data frome yfinance."""
|
51 |
+
# Step1. load data
|
52 |
+
dataframe = load_data(input.tickers)
|
53 |
+
# Step2. create plot
|
54 |
+
fig = visualization(dataframe)
|
55 |
+
# Step3. wrapped by output
|
56 |
+
output = PlotlyPlot(data=fig)
|
57 |
+
return output
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
workcell
|
2 |
+
yfinance
|
3 |
+
plotly
|
workcell.yaml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
workcell_name: stock_viewer
|
2 |
+
workcell_provider: huggingface
|
3 |
+
workcell_id: weanalyze/stock_viewer
|
4 |
+
workcell_version: latest
|
5 |
+
workcell_runtime: python3.8
|
6 |
+
workcell_entrypoint: app:stock_viewer
|
7 |
+
workcell_code:
|
8 |
+
ImageUri: ''
|
9 |
+
workcell_tags: {}
|
10 |
+
workcell_envs: {}
|