Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,6 @@ from chart_maker import ChartMaker
|
|
19 |
|
20 |
app = FastAPI(title="Pattern Analysis API")
|
21 |
|
22 |
-
# Add CORS middleware
|
23 |
app.add_middleware(
|
24 |
CORSMiddleware,
|
25 |
allow_origins=["*"],
|
@@ -28,19 +27,18 @@ app.add_middleware(
|
|
28 |
allow_headers=["*"],
|
29 |
)
|
30 |
|
31 |
-
# Global instances
|
32 |
pattern_analyzer = PatternAnalyzer()
|
33 |
indicator_analyzer = IndicatorAnalyzer()
|
34 |
chart_maker = ChartMaker()
|
35 |
|
36 |
-
async def analyze_stream(
|
37 |
async def generate():
|
38 |
try:
|
39 |
yield json.dumps({"status": "fetching_data"}) + "\n"
|
40 |
|
41 |
response = requests.get(
|
42 |
-
|
43 |
-
params={"
|
44 |
)
|
45 |
ohlcv_data = response.json()
|
46 |
|
@@ -66,7 +64,6 @@ async def analyze_stream(symbol: str, timeframe: str):
|
|
66 |
|
67 |
final_response = {
|
68 |
"status": "complete",
|
69 |
-
"symbol": symbol,
|
70 |
"timeframe": timeframe,
|
71 |
"patterns": patterns,
|
72 |
"indicators": indicators,
|
@@ -81,9 +78,9 @@ async def analyze_stream(symbol: str, timeframe: str):
|
|
81 |
|
82 |
return StreamingResponse(generate(), media_type="application/x-ndjson")
|
83 |
|
84 |
-
@app.get("/analyze
|
85 |
-
async def analyze_patterns(
|
86 |
-
return await analyze_stream(
|
87 |
|
88 |
@app.get("/")
|
89 |
def read_root():
|
|
|
19 |
|
20 |
app = FastAPI(title="Pattern Analysis API")
|
21 |
|
|
|
22 |
app.add_middleware(
|
23 |
CORSMiddleware,
|
24 |
allow_origins=["*"],
|
|
|
27 |
allow_headers=["*"],
|
28 |
)
|
29 |
|
|
|
30 |
pattern_analyzer = PatternAnalyzer()
|
31 |
indicator_analyzer = IndicatorAnalyzer()
|
32 |
chart_maker = ChartMaker()
|
33 |
|
34 |
+
async def analyze_stream(timeframe: str):
|
35 |
async def generate():
|
36 |
try:
|
37 |
yield json.dumps({"status": "fetching_data"}) + "\n"
|
38 |
|
39 |
response = requests.get(
|
40 |
+
"http://localhost:5000/codellama-chart-model",
|
41 |
+
params={"timeframe": timeframe}
|
42 |
)
|
43 |
ohlcv_data = response.json()
|
44 |
|
|
|
64 |
|
65 |
final_response = {
|
66 |
"status": "complete",
|
|
|
67 |
"timeframe": timeframe,
|
68 |
"patterns": patterns,
|
69 |
"indicators": indicators,
|
|
|
78 |
|
79 |
return StreamingResponse(generate(), media_type="application/x-ndjson")
|
80 |
|
81 |
+
@app.get("/analyze")
|
82 |
+
async def analyze_patterns(timeframe: str = "1D"):
|
83 |
+
return await analyze_stream(timeframe)
|
84 |
|
85 |
@app.get("/")
|
86 |
def read_root():
|