Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,7 @@ MEGA_EMAIL = os.environ.get("MEGA_EMAIL")
|
|
| 19 |
MEGA_PASSWORD = os.environ.get("MEGA_PASSWORD")
|
| 20 |
REMOTE_DESTINATION_PATH = os.environ.get("REMOTE_DESTINATION_PATH", "/Conversations/")
|
| 21 |
|
|
|
|
| 22 |
def persist_data(session_data):
|
| 23 |
if not MEGA_EMAIL or not MEGA_PASSWORD:
|
| 24 |
print("Warning: Mega credentials not configured.")
|
|
@@ -44,14 +45,16 @@ def persist_data(session_data):
|
|
| 44 |
with open(temp_log_path, "w", encoding="utf-8") as f:
|
| 45 |
f.write(formatted_log)
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
folder = m.find(REMOTE_DESTINATION_PATH)
|
| 49 |
if folder:
|
| 50 |
folder_id = folder[0]
|
| 51 |
-
m.upload(temp_log_path, folder_id)
|
| 52 |
else:
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
print(f"Log uploaded to Mega: {log_name}")
|
| 56 |
|
| 57 |
except Exception as e:
|
|
@@ -94,6 +97,8 @@ def respond(message, history: list[tuple[str, str]]):
|
|
| 94 |
for line in response.iter_lines():
|
| 95 |
if line:
|
| 96 |
line_text = line.decode('utf-8')
|
|
|
|
|
|
|
| 97 |
if line_text.startswith("data: "):
|
| 98 |
data_str = line_text[6:]
|
| 99 |
|
|
@@ -108,8 +113,9 @@ def respond(message, history: list[tuple[str, str]]):
|
|
| 108 |
token = delta['content']
|
| 109 |
accumulated_response += token
|
| 110 |
yield accumulated_response
|
| 111 |
-
except json.JSONDecodeError:
|
| 112 |
-
|
|
|
|
| 113 |
|
| 114 |
if not accumulated_response:
|
| 115 |
yield "Lo siento, ocurri贸 un error al procesar tu solicitud."
|
|
|
|
| 19 |
MEGA_PASSWORD = os.environ.get("MEGA_PASSWORD")
|
| 20 |
REMOTE_DESTINATION_PATH = os.environ.get("REMOTE_DESTINATION_PATH", "/Conversations/")
|
| 21 |
|
| 22 |
+
|
| 23 |
def persist_data(session_data):
|
| 24 |
if not MEGA_EMAIL or not MEGA_PASSWORD:
|
| 25 |
print("Warning: Mega credentials not configured.")
|
|
|
|
| 45 |
with open(temp_log_path, "w", encoding="utf-8") as f:
|
| 46 |
f.write(formatted_log)
|
| 47 |
|
| 48 |
+
# Buscar o crear carpeta en Mega
|
| 49 |
+
folder = m.find(REMOTE_DESTINATION_PATH.rstrip("/"))
|
| 50 |
if folder:
|
| 51 |
folder_id = folder[0]
|
|
|
|
| 52 |
else:
|
| 53 |
+
root_folder = m.find("/")
|
| 54 |
+
folder_id = m.create_folder(REMOTE_DESTINATION_PATH.strip("/"), root_folder[0])['f'][0]['h']
|
| 55 |
+
|
| 56 |
+
# Subir archivo
|
| 57 |
+
m.upload(temp_log_path, folder_id)
|
| 58 |
print(f"Log uploaded to Mega: {log_name}")
|
| 59 |
|
| 60 |
except Exception as e:
|
|
|
|
| 97 |
for line in response.iter_lines():
|
| 98 |
if line:
|
| 99 |
line_text = line.decode('utf-8')
|
| 100 |
+
|
| 101 |
+
# Solo procesamos las l铆neas que empiezan con "data: "
|
| 102 |
if line_text.startswith("data: "):
|
| 103 |
data_str = line_text[6:]
|
| 104 |
|
|
|
|
| 113 |
token = delta['content']
|
| 114 |
accumulated_response += token
|
| 115 |
yield accumulated_response
|
| 116 |
+
except json.JSONDecodeError as e:
|
| 117 |
+
print(f"JSON decode error: {e}, raw data: {data_str}")
|
| 118 |
+
continue # Saltamos l铆neas mal formadas
|
| 119 |
|
| 120 |
if not accumulated_response:
|
| 121 |
yield "Lo siento, ocurri贸 un error al procesar tu solicitud."
|