VasithaTilakumara commited on
Commit
ba6d1f3
Β·
1 Parent(s): 1583050

change local llm to huggingface inference API

Browse files
Files changed (4) hide show
  1. data/sim_history.csv +2 -2
  2. tabs/business.py +3 -2
  3. tabs/shared_ai.py +3 -0
  4. utils/models.py +21 -18
data/sim_history.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:adc5c709bdd68b50b40654913a0dbbd68040e2f95e1155a3e0fca503a8bd80ed
3
- size 3085
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1233d86c355f1f2a726e937fe03be88a8654c69724c776526d3a4125408ee213
3
+ size 3485
tabs/business.py CHANGED
@@ -101,8 +101,9 @@ def render():
101
  gr.Plot(plot_activity_heatmap(new_features_df))
102
 
103
  with gr.Column(elem_classes="card ai-chat"):
104
- # gr.HTML("<h3>πŸ€– Scenario Chat</h3>")
105
  respond,title = ai_chat_factory("Business Insights & What-If Analysis")
106
- gr.ChatInterface(fn=respond, chatbot=gr.Chatbot(label=title,height=290))
 
107
 
108
  # gr.HTML(f"<style>{css}</style>")
 
101
  gr.Plot(plot_activity_heatmap(new_features_df))
102
 
103
  with gr.Column(elem_classes="card ai-chat"):
104
+ gr.HTML("<h3> Scenario Chat : What-If Analysis</h3>")
105
  respond,title = ai_chat_factory("Business Insights & What-If Analysis")
106
+ # gr.ChatInterface(fn=respond, chatbot=gr.Chatbot(label=title,height=290))
107
+ gr.ChatInterface(fn=respond, chatbot=gr.Chatbot(type="messages",height=250))
108
 
109
  # gr.HTML(f"<style>{css}</style>")
tabs/shared_ai.py CHANGED
@@ -18,6 +18,9 @@ from pydantic import BaseModel, ValidationError
18
  # LangChain components
19
  from langchain_community.chat_models import ChatOllama, ChatHuggingFace
20
  from langchain_community.llms import HuggingFaceHub
 
 
 
21
  # from langchain.prompts import PromptTemplate
22
 
23
  # Local utilities
 
18
  # LangChain components
19
  from langchain_community.chat_models import ChatOllama, ChatHuggingFace
20
  from langchain_community.llms import HuggingFaceHub
21
+
22
+ from langchain_community.chat_models import ChatOllama
23
+ from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
24
  # from langchain.prompts import PromptTemplate
25
 
26
  # Local utilities
utils/models.py CHANGED
@@ -18,26 +18,29 @@ def load_model(model_path: str = "app_best.joblib"):
18
  Loads a trained scikit-learn model (.pkl or .joblib) from disk.
19
  Automatically searches in the /models folder if a relative path is provided.
20
  """
21
- # # Try direct path first
22
- # if os.path.exists(model_path):
23
- # return joblib.load(model_path)
24
-
25
- # # Try inside models/ folder
26
- # candidate_path = os.path.join("models", model_path)
27
- # if os.path.exists(candidate_path):
28
- # return joblib.load(candidate_path)
29
- # raise FileNotFoundError(
30
- # f"❌ Model file not found. Tried: {model_path_hf} and {model_path_hf}"
31
- # )
32
- # Download model dynamically from Hugging Face model repo
33
- model_path_hf = hf_hub_download(
34
- repo_id="VasTk/user-churn-models",
35
- filename=model_path
36
- )
37
- model = joblib.load(model_path_hf)
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
- return model
41
 
42
  # ------------------------------------------------------------
43
  # πŸ“Š Example placeholder metrics and visuals
 
18
  Loads a trained scikit-learn model (.pkl or .joblib) from disk.
19
  Automatically searches in the /models folder if a relative path is provided.
20
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ # Download model dynamically from Hugging Face model repo
23
+ if os.getenv("SPACE_ID"): # Running inside a Hugging Face Space
24
+ model_path_hf = hf_hub_download(
25
+ repo_id="VasTk/user-churn-models",
26
+ filename=model_path
27
+ )
28
+ model = joblib.load(model_path_hf)
29
+ return model
30
+ else:
31
+ # Try direct path first
32
+ if os.path.exists(model_path):
33
+ return joblib.load(model_path)
34
+
35
+ # Try inside models/ folder
36
+ candidate_path = os.path.join("models", model_path)
37
+ if os.path.exists(candidate_path):
38
+ return joblib.load(candidate_path)
39
+ raise FileNotFoundError(
40
+ f"❌ Model file not found. Tried: {model_path_hf} and {model_path_hf}"
41
+ )
42
+
43
 
 
44
 
45
  # ------------------------------------------------------------
46
  # πŸ“Š Example placeholder metrics and visuals