Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -714,17 +714,22 @@ class SmartAnalyzer:
|
|
| 714 |
except Exception as e:
|
| 715 |
raise Exception(f"Failed to calculate consistency: {str(e)}")
|
| 716 |
|
| 717 |
-
# Initialize storage and components
|
| 718 |
-
storage = ChatStorage()
|
| 719 |
-
analyzer = SmartAnalyzer(storage)
|
| 720 |
-
search_manager = AdvancedSearchManager(storage)
|
| 721 |
|
| 722 |
-
|
|
|
|
|
|
|
| 723 |
try:
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 728 |
|
| 729 |
|
| 730 |
# TWEAK JAWABAN MODEL
|
|
@@ -804,7 +809,6 @@ def groq_with_memory(message: str, topic: str = "general", retries: int = 3) ->
|
|
| 804 |
return f"β Error: {str(e)}", ""
|
| 805 |
|
| 806 |
|
| 807 |
-
|
| 808 |
def clear_all_history() -> Tuple[str, str, str]:
|
| 809 |
"""Clear all chat history and analytics data."""
|
| 810 |
try:
|
|
@@ -943,7 +947,14 @@ select {
|
|
| 943 |
}
|
| 944 |
"""
|
| 945 |
|
| 946 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 947 |
with gr.Blocks(
|
| 948 |
title="π€ AI Journal Chat with Analytics",
|
| 949 |
theme=gr.themes.Soft(),
|
|
|
|
| 714 |
except Exception as e:
|
| 715 |
raise Exception(f"Failed to calculate consistency: {str(e)}")
|
| 716 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 717 |
|
| 718 |
+
# Move get_topics_list here (before Gradio interface)
|
| 719 |
+
def get_topics_list() -> List[str]:
|
| 720 |
+
"""Retrieve a list of unique topics from the database, ensuring 'journal' is included."""
|
| 721 |
try:
|
| 722 |
+
with sqlite3.connect(DATABASE_FILE) as conn:
|
| 723 |
+
cursor = conn.execute('SELECT DISTINCT topic FROM messages ORDER BY topic')
|
| 724 |
+
topics = [row[0] for row in cursor.fetchall()]
|
| 725 |
+
if not topics:
|
| 726 |
+
return ["All Topics", "journal"]
|
| 727 |
+
if "journal" not in topics:
|
| 728 |
+
topics.append("journal")
|
| 729 |
+
return ["All Topics"] + sorted(topics)
|
| 730 |
+
except sqlite3.Error as e:
|
| 731 |
+
print(f"β Error retrieving topics: {str(e)}")
|
| 732 |
+
return ["All Topics", "journal"]
|
| 733 |
|
| 734 |
|
| 735 |
# TWEAK JAWABAN MODEL
|
|
|
|
| 809 |
return f"β Error: {str(e)}", ""
|
| 810 |
|
| 811 |
|
|
|
|
| 812 |
def clear_all_history() -> Tuple[str, str, str]:
|
| 813 |
"""Clear all chat history and analytics data."""
|
| 814 |
try:
|
|
|
|
| 947 |
}
|
| 948 |
"""
|
| 949 |
|
| 950 |
+
# Initialize storage and components (must be after get_topics_list)
|
| 951 |
+
storage = ChatStorage()
|
| 952 |
+
analyzer = SmartAnalyzer(storage)
|
| 953 |
+
search_manager = AdvancedSearchManager(storage)
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
|
| 957 |
+
# Main Gradio Interface (now get_topics_list is defined)
|
| 958 |
with gr.Blocks(
|
| 959 |
title="π€ AI Journal Chat with Analytics",
|
| 960 |
theme=gr.themes.Soft(),
|