DeMaking commited on
Commit
7a38f6d
·
verified ·
1 Parent(s): aac15bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -6,7 +6,7 @@ from transformers import pipeline
6
  import langid
7
  from huggingface_hub import login
8
  import socket
9
-
10
 
11
  # Global variables
12
  HF_HUB_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
@@ -26,9 +26,10 @@ english_generator = pipeline("text-generation", model="distilgpt2")
26
  # Function to detect language
27
  def detect_language(user_input):
28
  try:
 
29
  # lang = detect(user_input)
30
  lang, _ = langid.classify(user_input) # langid.classify returns a tuple (language, confidence)
31
- print(f"Detected language: {lang}")
32
  return "hebrew" if lang == "he" else "english" if lang == "en" else "unsupported"
33
  except Exception as e:
34
  print(f"Language detection error: {e}")
@@ -47,16 +48,16 @@ def detect_language(user_input):
47
 
48
  def generate_response(text):
49
  language = detect_language(text)
50
- print(f"Detected language: {language}") # Debugging
51
 
52
  if language == "hebrew":
53
  output = hebrew_generator(text, max_length=100, truncation=True)
54
- print(f"Hebrew model output: {output}") # Debugging
55
  return output[0]["generated_text"]
56
 
57
  elif language == "english":
58
  output = english_generator(text, max_length=100, truncation=True)
59
- print(f"English model output: {output}") # Debugging
60
  return output[0]["generated_text"]
61
 
62
  return "Sorry, I only support Hebrew and English."
 
6
  import langid
7
  from huggingface_hub import login
8
  import socket
9
+ import time
10
 
11
  # Global variables
12
  HF_HUB_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
 
26
  # Function to detect language
27
  def detect_language(user_input):
28
  try:
29
+ current_time = time.gmtime().tm_hour+2, ":" , time.gmtime().tm_min , ":" , time.gmtime().tm_sec
30
  # lang = detect(user_input)
31
  lang, _ = langid.classify(user_input) # langid.classify returns a tuple (language, confidence)
32
+ print(f"Detected language: {lang}", f"current time: {current_time}")
33
  return "hebrew" if lang == "he" else "english" if lang == "en" else "unsupported"
34
  except Exception as e:
35
  print(f"Language detection error: {e}")
 
48
 
49
  def generate_response(text):
50
  language = detect_language(text)
51
+ print(f"Detected language: {language}", f"current time: {current_time}") # Debugging
52
 
53
  if language == "hebrew":
54
  output = hebrew_generator(text, max_length=100, truncation=True)
55
+ print(f"Hebrew model output: {output}", f"current time: {current_time}") # Debugging
56
  return output[0]["generated_text"]
57
 
58
  elif language == "english":
59
  output = english_generator(text, max_length=100, truncation=True)
60
+ print(f"English model output: {output}", f"current time: {current_time}") # Debugging
61
  return output[0]["generated_text"]
62
 
63
  return "Sorry, I only support Hebrew and English."