diff --git "a/app.py" "b/app.py" --- "a/app.py" +++ "b/app.py" @@ -1,1157 +1,1575 @@ import streamlit as st -import os -from PIL import Image -# Set the page layout -st.set_page_config(layout="wide") -import json -import base64 -import time -from dotenv import load_dotenv -import os -import requests -import pickle +import pandas as pd +import joblib import numpy as np - -# Load model once -with open("best_clf.pkl", "rb") as file: - best_clf = pickle.load(file) - - -# Try loading environment variables locally -try: - from dotenv import load_dotenv - load_dotenv() -except: - pass - -# Get the token from environment variables -HF_TOKEN = os.environ.get("HF_TOKEN") - - -def query_huggingface_model(selected_model: dict, input_data, input_type="text",max_tokens=512,task="text-classification",temperature=0.7, top_p=0.9 ): - API_URL = selected_model.get("url") - headers = {"Authorization": f"Bearer {HF_TOKEN}"} - - try: - if input_type == "text": - if task == "text-generation": - payload = { - "messages": [ - { - "role": "user", - "content": input_data - } - ], - "model":selected_model.get("model") - } - - else: - payload = { - "inputs": input_data , - - } - response = requests.post(API_URL, headers=headers, json=payload) - - elif input_type == "image": - with open(input_data, "rb") as f: - data = f.read() - response = requests.post(API_URL, headers=headers, data=data) - - else: - return {"error": f"Unsupported input_type: {input_type}"} - - response.raise_for_status() - return response.json() - - except requests.exceptions.RequestException as e: - return {"error": str(e)} -def extract_response_content(response): - print(f"Response is: {response}") - - # For text generation or image captioning - if isinstance(response, list): - if response and isinstance(response[0], dict) and "generated_text" in response[0]: - return response[0]["generated_text"] - - elif response and isinstance(response[0], list) and "label" in response[0][0]: - # For text classification - return [(item["label"], round(item["score"], 3)) for item in response[0]] +import warnings +from streamlit.components.v1 import html +import time # For simulating loading +# --- Set page configuration --- +st.set_page_config( + page_title="CreditIQ - AI-Powered Credit Expenditure Prediction", + page_icon="π³", + layout="wide", # Use wide layout to better accommodate complex design + initial_sidebar_state="collapsed" # Hide sidebar to give full canvas +) +# --- Initialize session state for page management --- +if 'active_page' not in st.session_state: + st.session_state.active_page = 'home' +if 'show_prediction' not in st.session_state: + st.session_state.show_prediction = False +if 'predicted_value' not in st.session_state: + st.session_state.predicted_value = 0.0 - # For OpenAI-style chat responses - elif isinstance(response, dict): - if "choices" in response and isinstance(response["choices"], list): - try: - return response["choices"][0]["message"]["content"] - except (KeyError, IndexError, TypeError): - return "Error: Could not extract message from choices" - - elif "error" in response: - return f"Error: {response['error']}" - - return "Unknown response format" - -# --- Step 1 --- -if 'name' not in st.session_state: - st.session_state.name = "Paul" - -if 'gender' not in st.session_state: - st.session_state.gender = "Male" - -if 'age' not in st.session_state: - st.session_state.age = 25 - -if 'currentSmoker' not in st.session_state: - st.session_state.currentSmoker = "Yes" - -if 'cigsPerDay' not in st.session_state: - st.session_state.cigsPerDay = 0 - -if 'BPMeds' not in st.session_state: - st.session_state.BPMeds = False -if 'diabetes' not in st.session_state: - st.session_state.diabetes = False +warnings.filterwarnings('ignore') -# --- Step 2 --- -if 'totChol' not in st.session_state: - st.session_state.totChol = 180 # mg/dL - -if 'sysBP' not in st.session_state: - st.session_state.sysBP = 120 # mmHg - -if 'diaBP' not in st.session_state: - st.session_state.diaBP = 80 # mmHg - -# --- Step 3 --- -if 'BMI' not in st.session_state: - st.session_state.BMI = 22.0 - -if 'heartRate' not in st.session_state: - st.session_state.heartRate = 70 # bpm +st.markdown(""" + +""", unsafe_allow_html=True) +# --- Inject Custom HTML, CSS, and Inline JavaScript --- +# This block defines the sophisticated styling and background animations, +# navigation, and overall page structure. +# Streamlit components will be injected into specific HTML placeholders. +st.markdown(f""" + + +
+ + +Harness the power of advanced machine learning to accurately forecast credit card spending patterns and make informed financial decisions.
+Advanced algorithms analyze spending patterns
+Bank-level security for your data
+Instant predictions in seconds
+Discover what makes CreditIQ your ideal partner for financial insights.
+Leverage state-of-the-art machine learning models for highly precise expenditure forecasts.
+Your financial data is protected with industry-leading encryption and security protocols.
+We prioritize your privacy with strict data handling and anonymity measures.
+Access CreditIQ seamlessly on any device, from desktop to mobile.
+Understand your spending habits and gain insights to optimize your finances.
+Tailor prediction models to fit unique financial scenarios and individual needs.
+Our mission is to empower individuals and businesses with intelligent financial forecasting tools.
+CreditIQ was founded on the principle that informed financial decisions lead to greater stability and growth. We believe that by providing highly accurate, AI-driven credit expenditure predictions, we can help our users better manage their budgets, identify trends, and plan for the future with confidence.
+Our team of data scientists and financial experts has developed a robust platform that combines cutting-edge machine learning algorithms with user-friendly design. We are committed to continuous innovation and maintaining the highest standards of data security and privacy.
+Have questions, feedback, or need support? We're here to help.
+