Commit
·
baaf546
1
Parent(s):
0525575
updating req file
Browse files- api.py +11 -18
- rag_index/default__vector_store.json +0 -3
- rag_index/docstore.json +0 -3
- rag_index/graph_store.json +0 -3
- rag_index/image__vector_store.json +0 -3
- rag_index/index_store.json +0 -3
api.py
CHANGED
|
@@ -11,9 +11,10 @@ from bs4 import BeautifulSoup
|
|
| 11 |
import requests
|
| 12 |
import torch
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
-
|
| 15 |
from fastapi.middleware.cors import CORSMiddleware
|
| 16 |
|
|
|
|
| 17 |
MODEL_PATH = "lib/20_lstm_model.h5"
|
| 18 |
model = tf.keras.models.load_model(MODEL_PATH)
|
| 19 |
|
|
@@ -52,7 +53,6 @@ def fetch_and_process_ticker_data(ticker, start_date, end_date, interval="1d"):
|
|
| 52 |
temp["revenue"] = temp["adjclose"] * temp["volume"]
|
| 53 |
temp["daily_profit"] = temp["adjclose"] - temp["open"]
|
| 54 |
df = pd.concat([df, temp], axis=0)
|
| 55 |
-
df.to_csv("api_test.csv", index=False)
|
| 56 |
|
| 57 |
except Exception as error:
|
| 58 |
raise HTTPException(
|
|
@@ -291,17 +291,17 @@ async def fetch_ticker_data(ticker_name: str, start_date: str, end_date: str, in
|
|
| 291 |
raise HTTPException(status_code=500, detail=str(e))
|
| 292 |
|
| 293 |
|
| 294 |
-
@app.
|
| 295 |
-
async def predict_prices(
|
| 296 |
try:
|
| 297 |
-
|
| 298 |
-
ticker=
|
| 299 |
-
start_date=
|
| 300 |
-
end_date=
|
| 301 |
-
interval=
|
| 302 |
)
|
| 303 |
|
| 304 |
-
raw_data =
|
| 305 |
raw_data = raw_data.reset_index()
|
| 306 |
|
| 307 |
raw_data.rename(columns={"index": "date"}, inplace=True)
|
|
@@ -319,15 +319,13 @@ async def predict_prices(request: TickerRequest):
|
|
| 319 |
|
| 320 |
lstm_pred_df = storing_predictions(
|
| 321 |
temp_df, dates, stock, combined_dataset_prediction_inverse)
|
| 322 |
-
news_df = scrape_news(ticker_name=
|
| 323 |
|
| 324 |
combined_with_news_df = add_recent_news(lstm_pred_df, news_df)
|
| 325 |
sentiment_df = news_sentiment(combined_with_news_df)
|
| 326 |
|
| 327 |
sentiment_df['time_idx'] = range(1, len(sentiment_df) + 1)
|
| 328 |
|
| 329 |
-
print(sentiment_df)
|
| 330 |
-
|
| 331 |
predicted_values = get_tft_predictions(sentiment_df)
|
| 332 |
|
| 333 |
final_pred_open_price = predicted_values[0].item()
|
|
@@ -339,9 +337,4 @@ async def predict_prices(request: TickerRequest):
|
|
| 339 |
raise HTTPException(status_code=500, detail=str(e))
|
| 340 |
|
| 341 |
|
| 342 |
-
# @app.get("/query-rag/{user_query}")
|
| 343 |
-
# def query_rag(user_query: str):
|
| 344 |
-
|
| 345 |
-
# response = query_engine.query(user_query)
|
| 346 |
|
| 347 |
-
# return {'message': response}
|
|
|
|
| 11 |
import requests
|
| 12 |
import torch
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
+
import os
|
| 15 |
from fastapi.middleware.cors import CORSMiddleware
|
| 16 |
|
| 17 |
+
|
| 18 |
MODEL_PATH = "lib/20_lstm_model.h5"
|
| 19 |
model = tf.keras.models.load_model(MODEL_PATH)
|
| 20 |
|
|
|
|
| 53 |
temp["revenue"] = temp["adjclose"] * temp["volume"]
|
| 54 |
temp["daily_profit"] = temp["adjclose"] - temp["open"]
|
| 55 |
df = pd.concat([df, temp], axis=0)
|
|
|
|
| 56 |
|
| 57 |
except Exception as error:
|
| 58 |
raise HTTPException(
|
|
|
|
| 291 |
raise HTTPException(status_code=500, detail=str(e))
|
| 292 |
|
| 293 |
|
| 294 |
+
@app.get("/predict-prices/{ticker_name}/{start_date}/{end_date}/{interval}")
|
| 295 |
+
async def predict_prices(ticker_name: str, start_date: str, end_date: str, interval: str):
|
| 296 |
try:
|
| 297 |
+
result_df = fetch_and_process_ticker_data(
|
| 298 |
+
ticker=ticker_name,
|
| 299 |
+
start_date=start_date,
|
| 300 |
+
end_date=end_date,
|
| 301 |
+
interval=interval
|
| 302 |
)
|
| 303 |
|
| 304 |
+
raw_data = result_df.tail(60)
|
| 305 |
raw_data = raw_data.reset_index()
|
| 306 |
|
| 307 |
raw_data.rename(columns={"index": "date"}, inplace=True)
|
|
|
|
| 319 |
|
| 320 |
lstm_pred_df = storing_predictions(
|
| 321 |
temp_df, dates, stock, combined_dataset_prediction_inverse)
|
| 322 |
+
news_df = scrape_news(ticker_name=ticker_name)
|
| 323 |
|
| 324 |
combined_with_news_df = add_recent_news(lstm_pred_df, news_df)
|
| 325 |
sentiment_df = news_sentiment(combined_with_news_df)
|
| 326 |
|
| 327 |
sentiment_df['time_idx'] = range(1, len(sentiment_df) + 1)
|
| 328 |
|
|
|
|
|
|
|
| 329 |
predicted_values = get_tft_predictions(sentiment_df)
|
| 330 |
|
| 331 |
final_pred_open_price = predicted_values[0].item()
|
|
|
|
| 337 |
raise HTTPException(status_code=500, detail=str(e))
|
| 338 |
|
| 339 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
|
|
|
rag_index/default__vector_store.json
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:b07b216dd34042722c022963768ab830d48d385c645623e46afc83b37a4745c0
|
| 3 |
-
size 14374003
|
|
|
|
|
|
|
|
|
|
|
|
rag_index/docstore.json
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:bbf3547cf968b289a8fff77a16cb0143649df8424f45843822ad9c6853bf3d45
|
| 3 |
-
size 7500231
|
|
|
|
|
|
|
|
|
|
|
|
rag_index/graph_store.json
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:8e0a77744010862225c69da83c585f4f8a42fd551b044ce530dbb1eb6e16742c
|
| 3 |
-
size 18
|
|
|
|
|
|
|
|
|
|
|
|
rag_index/image__vector_store.json
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:d17ed74c1649a438e518a8dc56a7772913dfe1ea7a7605bce069c63872431455
|
| 3 |
-
size 72
|
|
|
|
|
|
|
|
|
|
|
|
rag_index/index_store.json
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:0128597297ccb9b86477e4805882f2501c988031e30cc651d857ad3a5a3b870c
|
| 3 |
-
size 133807
|
|
|
|
|
|
|
|
|
|
|
|