AAnvar commited on
Commit
d35079a
·
verified ·
1 Parent(s): a62a32c

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +27 -23
app.py CHANGED
@@ -1,20 +1,23 @@
1
 
2
- ######################## FINAL APP.PY #########################
3
- #07032025
4
- # import gradio as gr
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
- # Load config from local JSON file
17
- with open("/content/drive/MyDrive/Generative AI/Project 3/config.json") as f:
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
- # ------------------------ Gradio Interface ------------------------
85
- bot = NutritionBot()
86
-
87
- def respond(user_id, query):
88
- return bot.handle_customer_query(user_id, query)
89
-
90
- interface = gr.Interface(
91
- fn=respond,
92
- inputs=[
93
- gr.Textbox(label="User ID", placeholder="Enter your name or ID"),
94
- gr.Textbox(label="Query", placeholder="Ask about a nutrition disorder...")
95
- ],
96
- outputs=gr.Textbox(label="Agent Response"),
97
- title="Nutrition Disorder Specialist Agent",
98
- description="Ask me anything about nutrition-related health issues, treatments, and recommendations!"
99
- )
100
-
101
- interface.launch()
 
 
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))