Spaces:
Runtime error
Runtime error
| # 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 | |
| from core.stock_history import persist_response | |
| import os | |
| GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") | |
| llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", google_api_key=GOOGLE_API_KEY) | |
| def analyze_api(ticker): | |
| ticker_val = ticker.strip().upper() | |
| if ticker_val == "ALL_STOCKS": | |
| response = get_market_stock_sentiment(llm) | |
| persist_response(response) | |
| return response | |
| 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(show_error=True) | |