Spaces:
Runtime error
Runtime error
Commit
·
13aff77
1
Parent(s):
0595328
Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,11 @@ def format_prompt(message, history):
|
|
23 |
return prompt
|
24 |
|
25 |
# The main function to generate responses
|
26 |
-
def generate(prompt, history, temperature=0.1, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
|
|
|
|
|
|
|
|
27 |
temperature = float(temperature)
|
28 |
if temperature < 1e-2:
|
29 |
temperature = 1e-2
|
@@ -41,17 +45,19 @@ def generate(prompt, history, temperature=0.1, max_new_tokens=256, top_p=0.95, r
|
|
41 |
# Translate the Arabic prompt to English
|
42 |
english_prompt = translate_to_english(prompt)
|
43 |
|
|
|
44 |
formatted_prompt = format_prompt(english_prompt, history)
|
|
|
45 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
46 |
output = ""
|
47 |
|
48 |
for response in stream:
|
49 |
output += response.token.text
|
50 |
-
|
51 |
# Translate the English response back to Arabic
|
52 |
arabic_output = translate_to_arabic(output)
|
53 |
|
54 |
-
# Update the history state
|
55 |
history.append((prompt, arabic_output))
|
56 |
|
57 |
# Return the response and the updated state
|
|
|
23 |
return prompt
|
24 |
|
25 |
# The main function to generate responses
|
26 |
+
def generate(prompt, history=None, temperature=0.1, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
27 |
+
# Initialize history as an empty list if it's None
|
28 |
+
if history is None:
|
29 |
+
history = []
|
30 |
+
|
31 |
temperature = float(temperature)
|
32 |
if temperature < 1e-2:
|
33 |
temperature = 1e-2
|
|
|
45 |
# Translate the Arabic prompt to English
|
46 |
english_prompt = translate_to_english(prompt)
|
47 |
|
48 |
+
# Format the prompt with the conversation history
|
49 |
formatted_prompt = format_prompt(english_prompt, history)
|
50 |
+
|
51 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
52 |
output = ""
|
53 |
|
54 |
for response in stream:
|
55 |
output += response.token.text
|
56 |
+
|
57 |
# Translate the English response back to Arabic
|
58 |
arabic_output = translate_to_arabic(output)
|
59 |
|
60 |
+
# Update the history state with the latest exchange
|
61 |
history.append((prompt, arabic_output))
|
62 |
|
63 |
# Return the response and the updated state
|