Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
|
| 2 |
-
######################## FINAL APP.PY #########################
|
| 3 |
-
#07032025
|
| 4 |
-
|
| 5 |
import streamlit as st
|
| 6 |
from datetime import datetime
|
| 7 |
from typing import Dict, List
|
| 8 |
import os
|
| 9 |
import json
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
from mem0 import MemoryClient
|
| 12 |
from langchain_core.prompts import ChatPromptTemplate
|
| 13 |
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
| 14 |
from langchain.chat_models import ChatOpenAI
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
with open("
|
| 18 |
config = json.load(f)
|
| 19 |
|
| 20 |
# Optional placeholder if agentic_rag is not defined
|
|
@@ -81,21 +84,22 @@ class NutritionBot:
|
|
| 81 |
self.store_customer_interaction(user_id, query, response["output"], metadata={"type": "support_query"})
|
| 82 |
return response["output"]
|
| 83 |
|
| 84 |
-
# ------------------------
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
| 1 |
|
| 2 |
+
######################## FINAL APP.PY (Streamlit Version) #########################
|
| 3 |
+
# 07032025
|
| 4 |
+
|
| 5 |
import streamlit as st
|
| 6 |
from datetime import datetime
|
| 7 |
from typing import Dict, List
|
| 8 |
import os
|
| 9 |
import json
|
| 10 |
|
| 11 |
+
# ✅ Fix for Hugging Face write permission
|
| 12 |
+
os.environ["MEM0_HOME"] = "./.mem0"
|
| 13 |
+
|
| 14 |
from mem0 import MemoryClient
|
| 15 |
from langchain_core.prompts import ChatPromptTemplate
|
| 16 |
from langchain.agents import create_tool_calling_agent, AgentExecutor
|
| 17 |
from langchain.chat_models import ChatOpenAI
|
| 18 |
|
| 19 |
+
# ✅ Update: Use local config path (not Colab path)
|
| 20 |
+
with open("config.json") as f:
|
| 21 |
config = json.load(f)
|
| 22 |
|
| 23 |
# Optional placeholder if agentic_rag is not defined
|
|
|
|
| 84 |
self.store_customer_interaction(user_id, query, response["output"], metadata={"type": "support_query"})
|
| 85 |
return response["output"]
|
| 86 |
|
| 87 |
+
# ------------------------ Streamlit Interface ------------------------
|
| 88 |
+
|
| 89 |
+
st.set_page_config(page_title="Nutrition Disorder Specialist Agent")
|
| 90 |
+
st.title("🩺 Nutrition Disorder Specialist Agent")
|
| 91 |
+
st.write("Ask anything about nutrition-related disorders, treatments, or dietary recommendations.")
|
| 92 |
+
|
| 93 |
+
user_id = st.text_input("👤 User ID", placeholder="Enter your name or ID")
|
| 94 |
+
query = st.text_area("💬 Your Question", placeholder="Ask about a nutrition disorder...")
|
| 95 |
+
|
| 96 |
+
if st.button("🔍 Submit") and user_id and query:
|
| 97 |
+
with st.spinner("Thinking..."):
|
| 98 |
+
bot = NutritionBot()
|
| 99 |
+
try:
|
| 100 |
+
response = bot.handle_customer_query(user_id, query)
|
| 101 |
+
st.success("✅ Agent Response:")
|
| 102 |
+
st.write(response)
|
| 103 |
+
except Exception as e:
|
| 104 |
+
st.error("❌ Error occurred while processing your request.")
|
| 105 |
+
st.text(str(e))
|