Spaces:
Sleeping
Sleeping
Commit
·
a08e6a6
1
Parent(s):
cbc5d9e
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,17 +26,28 @@ def generate(prompt, history=[]):
|
|
| 26 |
# Call the format_prompt function to format the input for the model
|
| 27 |
formatted_prompt = format_prompt(prompt_in_english, history)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# Generate the response from the model
|
| 30 |
-
stream = client.text_generation(formatted_prompt, stream=True, details=True, return_full_text=False)
|
| 31 |
|
| 32 |
output = ""
|
| 33 |
for response in stream:
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
# Translate the English response back to Arabic
|
| 37 |
response_in_arabic = translate_to_arabic(output)
|
| 38 |
return response_in_arabic
|
| 39 |
|
|
|
|
| 40 |
iface = gr.Interface(
|
| 41 |
fn=generate,
|
| 42 |
inputs=[gr.Textbox(lines=5, placeholder='Type your Arabic query here...', label='Arabic Query')],
|
|
|
|
| 26 |
# Call the format_prompt function to format the input for the model
|
| 27 |
formatted_prompt = format_prompt(prompt_in_english, history)
|
| 28 |
|
| 29 |
+
generate_kwargs = {
|
| 30 |
+
"temperature": 0.1,
|
| 31 |
+
"max_new_tokens": 256,
|
| 32 |
+
"top_p": 0.95,
|
| 33 |
+
"repetition_penalty": 1.0,
|
| 34 |
+
"do_sample": True,
|
| 35 |
+
"seed": 42, # Seed for reproducibility, remove or change if randomness is preferred
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
# Generate the response from the model
|
| 39 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 40 |
|
| 41 |
output = ""
|
| 42 |
for response in stream:
|
| 43 |
+
if hasattr(response, 'text'): # Checks if the 'text' attribute is present
|
| 44 |
+
output += response.text
|
| 45 |
+
|
| 46 |
# Translate the English response back to Arabic
|
| 47 |
response_in_arabic = translate_to_arabic(output)
|
| 48 |
return response_in_arabic
|
| 49 |
|
| 50 |
+
|
| 51 |
iface = gr.Interface(
|
| 52 |
fn=generate,
|
| 53 |
inputs=[gr.Textbox(lines=5, placeholder='Type your Arabic query here...', label='Arabic Query')],
|