Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1742,17 +1742,21 @@ def format_stages_html(stages: List[Dict[str, str]], language: str, auto_scroll:
|
|
1742 |
|
1743 |
def get_active_sessions(language: str) -> List[Tuple[str, str, str]]:
|
1744 |
"""Get list of active sessions"""
|
1745 |
-
|
1746 |
-
|
1747 |
-
|
1748 |
-
|
1749 |
-
|
1750 |
-
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
|
|
|
|
|
|
|
|
|
1756 |
|
1757 |
def resume_session(session_id: str, language: str) -> Generator[Tuple[str, str, str], None, None]:
|
1758 |
"""Resume an existing session"""
|
@@ -2060,8 +2064,12 @@ def create_interface():
|
|
2060 |
return process, novel, status, novel
|
2061 |
|
2062 |
def refresh_sessions():
|
2063 |
-
|
2064 |
-
|
|
|
|
|
|
|
|
|
2065 |
|
2066 |
submit_btn.click(
|
2067 |
fn=process_query,
|
@@ -2127,6 +2135,11 @@ def create_interface():
|
|
2127 |
if __name__ == "__main__":
|
2128 |
logger.info("Starting SOMA Novel Writing System...")
|
2129 |
|
|
|
|
|
|
|
|
|
|
|
2130 |
interface = create_interface()
|
2131 |
|
2132 |
interface.launch(
|
|
|
1742 |
|
1743 |
def get_active_sessions(language: str) -> List[Tuple[str, str, str]]:
|
1744 |
"""Get list of active sessions"""
|
1745 |
+
try:
|
1746 |
+
sessions = NovelDatabase.get_active_sessions()
|
1747 |
+
|
1748 |
+
choices = []
|
1749 |
+
for session in sessions:
|
1750 |
+
created = datetime.fromisoformat(session['created_at'])
|
1751 |
+
date_str = created.strftime("%Y-%m-%d %H:%M")
|
1752 |
+
query_preview = session['user_query'][:50] + "..." if len(session['user_query']) > 50 else session['user_query']
|
1753 |
+
label = f"[{date_str}] {query_preview} (Stage {session['current_stage']})"
|
1754 |
+
choices.append((label, session['session_id']))
|
1755 |
+
|
1756 |
+
return choices
|
1757 |
+
except Exception as e:
|
1758 |
+
logger.error(f"Error getting active sessions: {str(e)}")
|
1759 |
+
return []
|
1760 |
|
1761 |
def resume_session(session_id: str, language: str) -> Generator[Tuple[str, str, str], None, None]:
|
1762 |
"""Resume an existing session"""
|
|
|
2064 |
return process, novel, status, novel
|
2065 |
|
2066 |
def refresh_sessions():
|
2067 |
+
try:
|
2068 |
+
sessions = get_active_sessions("English")
|
2069 |
+
return gr.update(choices=sessions)
|
2070 |
+
except Exception as e:
|
2071 |
+
logger.error(f"Error refreshing sessions: {str(e)}")
|
2072 |
+
return gr.update(choices=[])
|
2073 |
|
2074 |
submit_btn.click(
|
2075 |
fn=process_query,
|
|
|
2135 |
if __name__ == "__main__":
|
2136 |
logger.info("Starting SOMA Novel Writing System...")
|
2137 |
|
2138 |
+
# Initialize database on startup
|
2139 |
+
logger.info("Initializing database...")
|
2140 |
+
NovelDatabase.init_db()
|
2141 |
+
logger.info("Database initialized successfully.")
|
2142 |
+
|
2143 |
interface = create_interface()
|
2144 |
|
2145 |
interface.launch(
|