Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from langchain_groq import ChatGroq | |
| import yfinance as yf | |
| # Initialize the ChatGroq model using Hugging Face's secret management | |
| llm = ChatGroq(model_name="Llama3-8b-8192", api_key="groq_api_key") | |
| def fetch_stock_data(company_name): | |
| # Fetch stock data using Yahoo Finance | |
| ticker = yf.Ticker(company_name) | |
| stock_info = ticker.info | |
| # Extract relevant information | |
| stock_data = { | |
| "Company": stock_info.get("longName", "N/A"), | |
| "Current Price": stock_info.get("currentPrice", "N/A"), | |
| "Market Cap": stock_info.get("marketCap", "N/A"), | |
| "PE Ratio": stock_info.get("trailingPE", "N/A"), | |
| "Dividend Yield": stock_info.get("dividendYield", "N/A"), | |
| "52 Week High": stock_info.get("fiftyTwoWeekHigh", "N/A"), | |
| "52 Week Low": stock_info.get("fiftyTwoWeekLow", "N/A"), | |
| "Sector": stock_info.get("sector", "N/A"), | |
| "Industry": stock_info.get("industry", "N/A") | |
| } | |
| return stock_data | |
| def main(company_name): | |
| # Fetch stock data and generate a response | |
| stock_data = fetch_stock_data(company_name) | |
| # Prepare a response string | |
| response = f"Here is the data for {company_name}:\n" | |
| for key, value in stock_data.items(): | |
| response += f"{key}: {value}\n" | |
| return response | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=main, | |
| inputs="text", | |
| outputs="text", | |
| title="Stock Price Data Fetcher", | |
| description="Enter the company name or ticker symbol to get the latest stock price data." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |