Update app.py
Browse files
app.py
CHANGED
|
@@ -2,39 +2,49 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
import joblib
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
import streamlit as st
|
| 9 |
-
import huggingface_hub
|
| 10 |
|
| 11 |
# Display the version of huggingface_hub
|
|
|
|
| 12 |
st.write(f"Hugging Face Hub version: {huggingface_hub.__version__}")
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Function to load models safely
|
| 15 |
-
def load_model(
|
| 16 |
-
"""Loads a model
|
| 17 |
try:
|
| 18 |
-
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
-
st.error(f"Error loading model
|
| 21 |
return None
|
| 22 |
|
| 23 |
# Set repository ID and model filenames
|
| 24 |
REPO_ID = "totoro74/Intelligent_Customer_Analyzer"
|
| 25 |
|
| 26 |
-
# Load models
|
| 27 |
try:
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
bert_topic_model =
|
| 31 |
|
| 32 |
-
# Download and load Recommendation model
|
| 33 |
-
|
| 34 |
-
recommendation_model =
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
-
st.error(f"⚠️ Error loading models
|
| 38 |
|
| 39 |
# Streamlit app layout
|
| 40 |
st.title("📊 Intelligent Customer Feedback Analyzer")
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
import joblib
|
| 5 |
+
import requests
|
| 6 |
+
from io import BytesIO
|
| 7 |
+
from zipfile import ZipFile
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Display the version of huggingface_hub
|
| 10 |
+
import huggingface_hub
|
| 11 |
st.write(f"Hugging Face Hub version: {huggingface_hub.__version__}")
|
| 12 |
|
| 13 |
+
# Function to download models from Hugging Face using requests
|
| 14 |
+
def download_model_from_huggingface(repo_id, filename):
|
| 15 |
+
"""Downloads a model file from Hugging Face repository."""
|
| 16 |
+
url = f"https://huggingface.co/{repo_id}/resolve/main/{filename}"
|
| 17 |
+
response = requests.get(url)
|
| 18 |
+
if response.status_code == 200:
|
| 19 |
+
return BytesIO(response.content)
|
| 20 |
+
else:
|
| 21 |
+
raise Exception(f"Failed to download {filename}")
|
| 22 |
+
|
| 23 |
# Function to load models safely
|
| 24 |
+
def load_model(model_file):
|
| 25 |
+
"""Loads a model from a BytesIO object."""
|
| 26 |
try:
|
| 27 |
+
# Here we're assuming the model is in a `.joblib` file format
|
| 28 |
+
return joblib.load(model_file)
|
| 29 |
except Exception as e:
|
| 30 |
+
st.error(f"Error loading model: {e}")
|
| 31 |
return None
|
| 32 |
|
| 33 |
# Set repository ID and model filenames
|
| 34 |
REPO_ID = "totoro74/Intelligent_Customer_Analyzer"
|
| 35 |
|
| 36 |
+
# Load models using the download function
|
| 37 |
try:
|
| 38 |
+
# Download and load the BERTopic model
|
| 39 |
+
bert_topic_model_file = download_model_from_huggingface(REPO_ID, "models/bertopic_model.joblib")
|
| 40 |
+
bert_topic_model = load_model(bert_topic_model_file)
|
| 41 |
|
| 42 |
+
# Download and load the Recommendation model
|
| 43 |
+
recommendation_model_file = download_model_from_huggingface(REPO_ID, "models/recommendation_model.joblib")
|
| 44 |
+
recommendation_model = load_model(recommendation_model_file)
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
+
st.error(f"⚠️ Error loading models: {e}")
|
| 48 |
|
| 49 |
# Streamlit app layout
|
| 50 |
st.title("📊 Intelligent Customer Feedback Analyzer")
|