IZERE HIRWA Roger commited on
Commit
9d7bed2
·
1 Parent(s): f09b458
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -11,13 +11,15 @@ import smtplib
11
  import secrets
12
  import math
13
  import traceback
14
- import _time
15
  from flask import Flask, request, jsonify, send_from_directory, render_template, redirect
16
  from flask_cors import CORS
17
  # Replace direct ollama import with OpenAI client
18
  from openai import OpenAI
19
  from dotenv import load_dotenv
20
  from werkzeug.security import generate_password_hash, check_password_hash
 
 
 
21
  from translation_service import translation_service
22
  from sms_service import initialize_sms_service, get_sms_service
23
 
@@ -39,10 +41,7 @@ def _retry_openai_call(func, *args, _retries=1, _delay=0.5, **kwargs):
39
  last_err = e
40
  app.logger.warning(f"OpenAI call attempt {attempt + 1} failed: {e}")
41
  if attempt < _retries:
42
- try:
43
- _time.sleep(_delay)
44
- except Exception:
45
- pass
46
  else:
47
  raise last_err
48
 
@@ -63,10 +62,7 @@ def _retry_ollama_call(func, *args, _retries=1, _delay=0.5, **kwargs):
63
  except Exception:
64
  pass
65
  if attempt < _retries:
66
- try:
67
- _time.sleep(_delay)
68
- except Exception:
69
- pass
70
  else:
71
  raise last_err
72
 
@@ -900,7 +896,7 @@ CORS(app, resources={r"/*": {"origins": "*"}},
900
  # Initialize SMS service
901
  initialize_sms_service(HDEV_SMS_API_ID, HDEV_SMS_API_KEY)
902
 
903
- # --- Public landing page routes (serve files from chatbot/ without affecting APIs) ---
904
  _CHATBOT_STATIC_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'chatbot')
905
 
906
  @app.route('/')
@@ -1678,6 +1674,10 @@ Rappelez-vous: Vous êtes un système professionnel de soutien en santé mentale
1678
 
1679
  'rw': """Uri AIMHSA, umufasha w'ubuzima bw'ubwoba bw'u Rwanda w'ubuhanga.
1680
 
 
 
 
 
1681
  Amabwiriza y'ubuhanga:
1682
  - Ube umuntu w'umutima mwiza, w'umutima mwiza, kandi w'umutima mwiza
1683
  - Tanga amakuru yashyizweho ku bikoresho byo mu cyerekezo mugihe cyose
 
11
  import secrets
12
  import math
13
  import traceback
 
14
  from flask import Flask, request, jsonify, send_from_directory, render_template, redirect
15
  from flask_cors import CORS
16
  # Replace direct ollama import with OpenAI client
17
  from openai import OpenAI
18
  from dotenv import load_dotenv
19
  from werkzeug.security import generate_password_hash, check_password_hash
20
+ from datetime import datetime
21
+ from werkzeug.utils import secure_filename
22
+ from typing import Dict, List, Tuple, Optional
23
  from translation_service import translation_service
24
  from sms_service import initialize_sms_service, get_sms_service
25
 
 
41
  last_err = e
42
  app.logger.warning(f"OpenAI call attempt {attempt + 1} failed: {e}")
43
  if attempt < _retries:
44
+ time.sleep(_delay) # Use time.sleep instead of _time.sleep
 
 
 
45
  else:
46
  raise last_err
47
 
 
62
  except Exception:
63
  pass
64
  if attempt < _retries:
65
+ time.sleep(_delay) # Use time.sleep instead of _time.sleep
 
 
 
66
  else:
67
  raise last_err
68
 
 
896
  # Initialize SMS service
897
  initialize_sms_service(HDEV_SMS_API_ID, HDEV_SMS_API_KEY)
898
 
899
+ # --- Public landing page routes (serve files from chatbot/without affecting APIs) ---
900
  _CHATBOT_STATIC_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'chatbot')
901
 
902
  @app.route('/')
 
1674
 
1675
  'rw': """Uri AIMHSA, umufasha w'ubuzima bw'ubwoba bw'u Rwanda w'ubuhanga.
1676
 
1677
+ Amabwiriza y'ubuhanga:
1678
+ - Ube umuntu w'umutima mwiza, w'umutima mwiza, kandi w'umutima mwiza
1679
+ - Tanga amakuru yashyizweho ku bikoresho byo mu cyerekezo mugihe cyose
1680
+ - VUGURA BURI
1681
  Amabwiriza y'ubuhanga:
1682
  - Ube umuntu w'umutima mwiza, w'umutima mwiza, kandi w'umutima mwiza
1683
  - Tanga amakuru yashyizweho ku bikoresho byo mu cyerekezo mugihe cyose