DeMaking commited on
Commit
489d405
·
verified ·
1 Parent(s): 18e57f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -8,19 +8,18 @@ from huggingface_hub import login
8
  # Initialize Flask app
9
  app = Flask(__name__)
10
 
11
- # Gets the Token from secrect
12
  hf_hub_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
13
-
14
- # Logging in
15
  login(token=hf_hub_token)
16
 
17
- # Load Hebrew models (classification + text generation)
18
- hebrew_classifier = pipeline("text-classification", model="onlplab/alephbert-base")
19
- hebrew_generator = pipeline("text2text-generation", model="google/mt5-small")
20
 
21
- # Load English models
22
- english_classifier = pipeline("text-classification", model="mistralai/Mistral-7B-Instruct-v0.3")
23
- english_generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
 
 
24
 
25
  # Function to detect language
26
  def detect_language(user_input):
@@ -42,13 +41,11 @@ def generate_response(text):
42
  language = detect_language(text)
43
 
44
  if language == "hebrew":
45
- classification = hebrew_classifier(text)
46
  response = hebrew_generator(text, max_length=100)[0]["generated_text"]
47
  elif language == "english":
48
- classification = english_classifier(text)
49
  response = english_generator(text, max_length=100)[0]["generated_text"]
50
  else:
51
- response = "Sorry, I only support Hebrew and English."
52
 
53
  return response
54
 
@@ -69,7 +66,7 @@ def ask():
69
  # Root endpoint
70
  @app.route("/")
71
  def home():
72
- return "Decision Helper Bot API is running!"
73
 
74
  if __name__ == "__main__":
75
  logging.basicConfig(level=logging.INFO)
 
8
  # Initialize Flask app
9
  app = Flask(__name__)
10
 
11
+ # Gets the Token from secrects and Login if exists
12
  hf_hub_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
13
+ if not hf_hub_token:
14
+ raise ValueError("Missing Hugging Face API token. Please set HUGGINGFACEHUB_API_TOKEN in environment variables.")
15
  login(token=hf_hub_token)
16
 
 
 
 
17
 
18
+ # Load Hebrew text generation model
19
+ hebrew_generator = pipeline("text-generation", model="google/mt5-small", tokenizer="google/mt5-small")
20
+
21
+ # Load English text generation model
22
+ english_generator = pipeline("text-generation", model="distilgpt2")
23
 
24
  # Function to detect language
25
  def detect_language(user_input):
 
41
  language = detect_language(text)
42
 
43
  if language == "hebrew":
 
44
  response = hebrew_generator(text, max_length=100)[0]["generated_text"]
45
  elif language == "english":
 
46
  response = english_generator(text, max_length=100)[0]["generated_text"]
47
  else:
48
+ response = "Sorry, I only support Hebrew and English."
49
 
50
  return response
51
 
 
66
  # Root endpoint
67
  @app.route("/")
68
  def home():
69
+ return "Decision Making Helper Bot API is running!"
70
 
71
  if __name__ == "__main__":
72
  logging.basicConfig(level=logging.INFO)