Spaces:
Paused
Paused
| import streamlit as st | |
| import pandas as pd | |
| from gradio_client import Client | |
| # Fetch the Hugging Face token from Streamlit secrets | |
| hf_token = st.secrets["hf_tok"] | |
| # Set up Hugging Face API client | |
| client = Client("theprasenjeet/gradio-nifty-outperformer", hf_token=hf_token) | |
| def load_index_data(): | |
| url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vT4gaeQybFavD-hG6UUW3lZ_yAI05TuZF-W_ZZFvCak3pa_mKv9dAlHCicmY45e84oGcLNJ7gJCyQ4V/pub?gid=0&single=true&output=csv" | |
| index_data = pd.read_csv(url) | |
| return index_data["Symbol"].tolist() | |
| index_options = load_index_data() | |
| period_options = ['1M', '3M', '6M', '1Yr', '3Yr', '5Yr', '10Yr'] | |
| sector_options = ['All', 'Consumer Defensive', 'Consumer Cyclical', 'Industrials', 'Basic Materials', 'Communication Services', 'Healthcare', 'Financial Services', 'Energy', 'Utilities', 'Real Estate', 'Technology'] | |
| industry_options =['All', 'Confectioners', 'Textile Manufacturing', 'Beverages - Non-Alcoholic', 'Specialty Business Services', 'Furnishings, Fixtures & Appliances', 'Auto Parts', 'Building Products & Equipment', 'Specialty Chemicals', 'Lodging', 'Entertainment', 'Drug Manufacturers - Specialty & Generic', 'Electrical Equipment & Parts', 'Asset Management', 'Capital Markets', 'Financial Data & Stock Exchanges', 'Airports & Air Services', 'Engineering & Construction', 'Luxury Goods', 'Thermal Coal', 'Specialty Industrial Machinery', 'Leisure', 'Steel', 'Infrastructure Operations', 'Agricultural Inputs', 'Credit Services', 'Utilities - Regulated Gas', 'Aluminum', 'Marine Shipping', 'Auto Manufacturers', 'Biotechnology', 'Apparel Retail', 'Integrated Freight & Logistics', 'Packaged Foods', 'Apparel Manufacturing', 'Chemicals', 'Packaging & Containers', 'Real Estate Services', 'Mortgage Finance', 'Other Industrial Metals & Mining', 'Paper & Paper Products', 'Footwear & Accessories', 'Real Estate - Development', 'Telecom Services', 'Software - Application', 'Conglomerates', 'Metal Fabrication', 'Communication Equipment', 'Computer Hardware', 'Drug Manufacturers - General', 'Real Estate - Diversified', 'Medical Care Facilities', 'Utilities - Renewable', 'Farm & Heavy Construction Machinery', 'Software - Infrastructure', 'Banks - Regional', 'Information Technology Services', 'Shell Companies', 'Financial Conglomerates', 'Broadcasting', 'Solar', 'Electronic Components', 'Oil & Gas E&P', 'Building Materials', 'Oil & Gas Refining & Marketing', 'Aerospace & Defense', 'Railroads', 'Publishing', 'Utilities - Independent Power Producers', 'Household & Personal Products', 'Pharmaceutical Retailers', 'Scientific & Technical Instruments', 'Insurance - Life', 'Waste Management', 'Home Improvement Retail', 'Beverages - Brewers', 'Business Equipment & Supplies', 'Tools & Accessories', 'Security & Protection Services', 'Rental & Leasing Services', 'Consumer Electronics', 'Auto & Truck Dealerships', 'Internet Content & Information', 'Lumber & Wood Production', 'Education & Training Services', 'Department Stores', 'Beverages - Wineries & Distilleries', 'Farm Products', 'Medical Instruments & Supplies', 'Tobacco', 'Airlines', 'Oil & Gas Equipment & Services', 'Utilities - Regulated Electric', 'Restaurants', 'Internet Retail', 'Travel Services', 'Drug Manufacturers—Specialty & Generic', 'Real Estate—Development', 'Banks—Regional', 'Copper', 'Utilities—Regulated Gas', 'Food Distribution', 'Drug Manufacturers—General', 'Software—Application', 'Oil & Gas Integrated', 'Pollution & Treatment Controls', 'Utilities—Regulated Electric', 'Utilities—Independent Power Producers', 'Insurance—Diversified', 'Consulting Services', 'Advertising Agencies', 'Beverages—Wineries & Distilleries', 'Beverages—Brewers', 'Software—Infrastructure', 'Utilities—Renewable', 'Insurance—Life', 'Diagnostics & Research', 'Electronics & Computer Distribution', 'Medical Devices', 'Real Estate—Diversified', 'Trucking', 'Insurance—Property & Casualty', 'Insurance—Reinsurance', 'Resorts & Casinos', 'Specialty Retail', 'Staffing & Employment Services', 'Electronic Gaming & Multimedia', 'Medical Distribution', 'Discount Stores', 'Beverages—Non-Alcoholic', 'Healthcare Plans', 'Insurance Brokers', 'Health Information Services', 'Oil & Gas Drilling'] | |
| st.title("Nifty Outperformer App") | |
| selected_index = st.selectbox("Select Index:", index_options) | |
| selected_period = st.selectbox("Select Period:", period_options, index=3) | |
| # Radio button to choose between Sector and Industry | |
| selection_type = st.radio("Select filter type:", ("Sector", "Industry")) | |
| if selection_type == "Sector": | |
| selected_sector = st.selectbox("Select Sector:", sector_options, index=0) | |
| selected_industry = "All" # Reset industry selection | |
| else: | |
| selected_industry = st.selectbox("Select Industry:", industry_options, index=0) | |
| selected_sector = "All" # Reset sector selection | |
| if st.button("Get Top 100"): | |
| # Fetch the data | |
| result = client.predict( | |
| selected_index=selected_index, | |
| selected_period=selected_period, | |
| selected_sector=selected_sector, | |
| selected_industry=selected_industry, | |
| api_name="/display_top_stocks" | |
| ) | |
| # Check if result is in expected format | |
| try: | |
| # Extract headers and data | |
| headers = result["headers"] | |
| data = result["data"] | |
| # Create DataFrame | |
| df_result = pd.DataFrame(data, columns=headers) | |
| # Display the DataFrame in table format | |
| st.subheader("Top 100 Outperforming Stocks") | |
| st.table(df_result) # Display as a table for readability | |
| except Exception as e: | |
| st.error(f"Error processing result: {e}") | |
| else: | |
| st.info("Please select options and click 'Get Top 100' to view results.") |