Spaces:
Runtime error
Runtime error
Commit
·
0595328
1
Parent(s):
94b1e53
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ def generate(prompt, history, temperature=0.1, max_new_tokens=256, top_p=0.95, r
|
|
28 |
if temperature < 1e-2:
|
29 |
temperature = 1e-2
|
30 |
top_p = float(top_p)
|
31 |
-
|
32 |
generate_kwargs = dict(
|
33 |
temperature=temperature,
|
34 |
max_new_tokens=max_new_tokens,
|
@@ -37,20 +37,25 @@ def generate(prompt, history, temperature=0.1, max_new_tokens=256, top_p=0.95, r
|
|
37 |
do_sample=True,
|
38 |
seed=42,
|
39 |
)
|
40 |
-
|
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 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
# Additional input widgets for controlling the generation parameters
|
56 |
additional_inputs = [
|
@@ -93,14 +98,19 @@ additional_inputs = [
|
|
93 |
]
|
94 |
|
95 |
# Creating and launching the Gradio interface
|
96 |
-
gr.Interface(
|
97 |
fn=generate,
|
98 |
inputs=[
|
99 |
-
gr.Textbox(lines=2,
|
100 |
-
gr.State()
|
101 |
-
|
|
|
|
|
|
|
102 |
],
|
103 |
-
outputs=gr.Textbox(label="Generated Response in Arabic"),
|
104 |
title="Try Arabic Misteral",
|
105 |
description="Interact with an advanced AI model in Arabic. Adjust the settings below to tailor the responses. Your prompts will be translated to English, processed by the AI, and the response will be translated back to Arabic."
|
106 |
-
)
|
|
|
|
|
|
|
|
28 |
if temperature < 1e-2:
|
29 |
temperature = 1e-2
|
30 |
top_p = float(top_p)
|
31 |
+
|
32 |
generate_kwargs = dict(
|
33 |
temperature=temperature,
|
34 |
max_new_tokens=max_new_tokens,
|
|
|
37 |
do_sample=True,
|
38 |
seed=42,
|
39 |
)
|
40 |
+
|
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
|
58 |
+
return arabic_output, history
|
59 |
|
60 |
# Additional input widgets for controlling the generation parameters
|
61 |
additional_inputs = [
|
|
|
98 |
]
|
99 |
|
100 |
# Creating and launching the Gradio interface
|
101 |
+
iface = gr.Interface(
|
102 |
fn=generate,
|
103 |
inputs=[
|
104 |
+
gr.Textbox(lines=2, placeholder="Enter your prompt in Arabic"),
|
105 |
+
gr.State() # State input to maintain the conversation history
|
106 |
+
] + additional_inputs,
|
107 |
+
outputs=[
|
108 |
+
gr.Textbox(placeholder="Generated response in Arabic"),
|
109 |
+
gr.State() # State output to maintain the conversation history
|
110 |
],
|
|
|
111 |
title="Try Arabic Misteral",
|
112 |
description="Interact with an advanced AI model in Arabic. Adjust the settings below to tailor the responses. Your prompts will be translated to English, processed by the AI, and the response will be translated back to Arabic."
|
113 |
+
)
|
114 |
+
|
115 |
+
# Launch the interface
|
116 |
+
iface.launch()
|