stock-api / app.py
rajat5ranjan's picture
Update app.py
fc49341 verified
raw
history blame contribute delete
906 Bytes
# app.py
import gradio as gr
from core.stock_analysis import analyze_stock
from core.market_stock_sentiment import get_market_stock_sentiment
from langchain_google_genai import ChatGoogleGenerativeAI
import os
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
llm = ChatGoogleGenerativeAI(model="gemini-2.5-pro", google_api_key=GOOGLE_API_KEY)
def analyze_api(ticker):
ticker_val = ticker.strip().upper()
if ticker_val == "ALL_STOCKS":
return get_market_stock_sentiment(llm)
else:
return analyze_stock(ticker_val, llm)
demo = gr.Interface(
fn=analyze_api,
inputs=gr.Textbox(label="Enter NSE Ticker (e.g., RELIANCE)"),
outputs="json",
title="πŸ“ˆ Stock Analysis API (NSE)",
description="Get analysis and insights for Indian stocks using Google Gemini + LangChain. Returns structured JSON."
)
if __name__ == "__main__":
demo.queue(api_open=True).launch()