Update app.py
Browse files
app.py
CHANGED
|
@@ -22,10 +22,6 @@ login(token=HF_HUB_TOKEN)
|
|
| 22 |
|
| 23 |
client = InferenceClient(api_key=HF_HUB_TOKEN)
|
| 24 |
|
| 25 |
-
# Load Hebrew and English text generation models
|
| 26 |
-
# lang_generator = pipeline("text-generation", model="microsoft/Phi-3.5-mini-instruct")
|
| 27 |
-
|
| 28 |
-
|
| 29 |
# Function to detect language
|
| 30 |
def detect_language(user_input):
|
| 31 |
try:
|
|
@@ -40,10 +36,7 @@ def detect_language(user_input):
|
|
| 40 |
def generate_response(text):
|
| 41 |
language = detect_language(text)
|
| 42 |
print(f"Detected language: {language}, ", f"current time: {current_time_gmt()}")
|
| 43 |
-
|
| 44 |
-
#template = "Use the text in the question as context to answer the question at the end.\
|
| 45 |
-
#If you don't know the answer, just say that you don't know, don't try to make up an answer."
|
| 46 |
-
|
| 47 |
if language == "hebrew" or language == "english":
|
| 48 |
messages = [
|
| 49 |
{ "role": "user", "content": text }
|
|
@@ -53,12 +46,12 @@ def generate_response(text):
|
|
| 53 |
completion = client.chat.completions.create(
|
| 54 |
model="microsoft/Phi-3.5-mini-instruct",
|
| 55 |
messages=messages,
|
| 56 |
-
max_tokens=
|
| 57 |
temperature=0.5,
|
| 58 |
top_p=0.7
|
| 59 |
)
|
| 60 |
-
print("\ncompletion: ", completion.choices[0].message, f"\ncurrent time: {current_time_gmt()}")
|
| 61 |
-
return completion.choices[0].message
|
| 62 |
|
| 63 |
return "Sorry, I only support Hebrew and English."
|
| 64 |
|
|
|
|
| 22 |
|
| 23 |
client = InferenceClient(api_key=HF_HUB_TOKEN)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Function to detect language
|
| 26 |
def detect_language(user_input):
|
| 27 |
try:
|
|
|
|
| 36 |
def generate_response(text):
|
| 37 |
language = detect_language(text)
|
| 38 |
print(f"Detected language: {language}, ", f"current time: {current_time_gmt()}")
|
| 39 |
+
|
|
|
|
|
|
|
|
|
|
| 40 |
if language == "hebrew" or language == "english":
|
| 41 |
messages = [
|
| 42 |
{ "role": "user", "content": text }
|
|
|
|
| 46 |
completion = client.chat.completions.create(
|
| 47 |
model="microsoft/Phi-3.5-mini-instruct",
|
| 48 |
messages=messages,
|
| 49 |
+
max_tokens=500,
|
| 50 |
temperature=0.5,
|
| 51 |
top_p=0.7
|
| 52 |
)
|
| 53 |
+
print("\ncompletion: ", completion.choices[0].message.content, f"\ncurrent time: {current_time_gmt()}")
|
| 54 |
+
return completion.choices[0].message.content
|
| 55 |
|
| 56 |
return "Sorry, I only support Hebrew and English."
|
| 57 |
|