Dooratre commited on
Commit
c9449a0
·
verified ·
1 Parent(s): 65f4436

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -19,6 +19,7 @@ MESSAGE_API_URL = "https://aoamrnuwara.pythonanywhere.com/api/send-message"
19
  MESSAGE_API_KEY = "Seakp0683asppoit2"
20
  SCREENSHOT_API_URL = "https://corvo-ai-xx-sc.hf.space/capture"
21
  AI_API_URL = "https://corvo-ai-xx-gpt-5.hf.space/chat"
 
22
  ALERT_API_URL = "https://dooratre-alert.hf.space/monitor"
23
 
24
  # إعدادات المحاولات
@@ -48,7 +49,14 @@ def thinking_animation():
48
  print(".", end="", flush=True)
49
  time.sleep(0.5)
50
 
51
- def call_o1_ai_api(formatted_chat_history):
 
 
 
 
 
 
 
52
  headers = {"Content-Type": "application/json"}
53
  payload = {"chat_history": formatted_chat_history}
54
  timeout = 600
@@ -57,7 +65,7 @@ def call_o1_ai_api(formatted_chat_history):
57
  try:
58
  print("AI THINKING", end="", flush=True)
59
  thinking_animation()
60
- response = requests.post(AI_API_URL, headers=headers, data=json.dumps(payload), timeout=timeout)
61
  response.raise_for_status()
62
  assistant_response = response.json().get("assistant_response", "No response received.")
63
  formatted_chat_history.append({"role": "assistant", "content": assistant_response})
@@ -988,7 +996,8 @@ def analysis_now():
988
  logger.info(f"🔔 Received alert message: {alert_message}")
989
 
990
  chat_history = build_chat_history(alert_message)
991
- ai_response, updated_chat = call_o1_ai_api(chat_history)
 
992
 
993
  tag_counts = count_xml_tags(ai_response)
994
  logger.info(f"📊 XML tags found: {tag_counts}")
@@ -1019,7 +1028,8 @@ def start_analysis():
1019
  try:
1020
  logger.info("🚀 Starting initial analysis...")
1021
  chat_history = build_chat_history()
1022
- ai_response, updated_chat = call_o1_ai_api(chat_history)
 
1023
 
1024
  tag_counts = count_xml_tags(ai_response)
1025
  logger.info(f"📊 XML tags found: {tag_counts}")
 
19
  MESSAGE_API_KEY = "Seakp0683asppoit2"
20
  SCREENSHOT_API_URL = "https://corvo-ai-xx-sc.hf.space/capture"
21
  AI_API_URL = "https://corvo-ai-xx-gpt-5.hf.space/chat"
22
+ AI_API_URL_O1 = "https://corvo-ai-xx-o1.hf.space/chat"
23
  ALERT_API_URL = "https://dooratre-alert.hf.space/monitor"
24
 
25
  # إعدادات المحاولات
 
49
  print(".", end="", flush=True)
50
  time.sleep(0.5)
51
 
52
+ def has_active_signal():
53
+ try:
54
+ signals_data = db_signals.fetch_json_from_github()
55
+ return bool(signals_data and signals_data.get("success") and signals_data.get("data"))
56
+ except Exception:
57
+ return False
58
+
59
+ def call_o1_ai_api(formatted_chat_history, api_url=AI_API_URL):
60
  headers = {"Content-Type": "application/json"}
61
  payload = {"chat_history": formatted_chat_history}
62
  timeout = 600
 
65
  try:
66
  print("AI THINKING", end="", flush=True)
67
  thinking_animation()
68
+ response = requests.post(api_url, headers=headers, data=json.dumps(payload), timeout=timeout)
69
  response.raise_for_status()
70
  assistant_response = response.json().get("assistant_response", "No response received.")
71
  formatted_chat_history.append({"role": "assistant", "content": assistant_response})
 
996
  logger.info(f"🔔 Received alert message: {alert_message}")
997
 
998
  chat_history = build_chat_history(alert_message)
999
+ api_url = AI_API_URL_O1 if has_active_signal() else AI_API_URL
1000
+ ai_response, updated_chat = call_o1_ai_api(chat_history, api_url=api_url)
1001
 
1002
  tag_counts = count_xml_tags(ai_response)
1003
  logger.info(f"📊 XML tags found: {tag_counts}")
 
1028
  try:
1029
  logger.info("🚀 Starting initial analysis...")
1030
  chat_history = build_chat_history()
1031
+ api_url = AI_API_URL_O1 if has_active_signal() else AI_API_URL
1032
+ ai_response, updated_chat = call_o1_ai_api(chat_history, api_url=api_url)
1033
 
1034
  tag_counts = count_xml_tags(ai_response)
1035
  logger.info(f"📊 XML tags found: {tag_counts}")