Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,6 +49,25 @@ gemma_3_formatter = MessagesFormatter(
|
|
| 49 |
eos_token="<eos>", # End of sequence token for Gemma 3
|
| 50 |
)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Set the title and description
|
| 54 |
title = "Kazakh Language Model"
|
|
@@ -62,7 +81,7 @@ def respond(
|
|
| 62 |
message: str,
|
| 63 |
history: List[Tuple[str, str]],
|
| 64 |
model: str = "gemma_3_800M_sft_v2_translation-kazparc_latest.gguf", # Set default model
|
| 65 |
-
|
| 66 |
max_tokens: int = 64,
|
| 67 |
temperature: float = 0.7,
|
| 68 |
top_p: float = 0.95,
|
|
@@ -132,16 +151,16 @@ def respond(
|
|
| 132 |
|
| 133 |
messages = BasicChatHistory()
|
| 134 |
|
| 135 |
-
|
| 136 |
-
for
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
messages.add_message(
|
| 140 |
-
|
| 141 |
|
| 142 |
# Get the response stream
|
| 143 |
stream = agent.get_chat_response(
|
| 144 |
-
|
| 145 |
llm_sampling_settings=settings,
|
| 146 |
chat_history=messages,
|
| 147 |
returns_streaming_generator=True,
|
|
@@ -172,12 +191,9 @@ demo = gr.ChatInterface(
|
|
| 172 |
),
|
| 173 |
additional_inputs=[
|
| 174 |
gr.Dropdown(
|
| 175 |
-
choices=[
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
value="gemma_3_800M_sft_v2_translation-kazparc_latest.gguf",
|
| 179 |
-
label="Model",
|
| 180 |
-
info="Select the AI model to use for chat",
|
| 181 |
),
|
| 182 |
gr.Textbox(
|
| 183 |
value="You are a helpful assistant.",
|
|
|
|
| 49 |
eos_token="<eos>", # End of sequence token for Gemma 3
|
| 50 |
)
|
| 51 |
|
| 52 |
+
# Translation direction to prompts mapping
|
| 53 |
+
direction_to_prompts = {
|
| 54 |
+
"English to Kazakh": {
|
| 55 |
+
"system": "You are a professional translator. Translate the following sentence into қазақ.",
|
| 56 |
+
"prefix": "<src=en><tgt=kk>"
|
| 57 |
+
},
|
| 58 |
+
"Kazakh to English": {
|
| 59 |
+
"system": "Сіз кәсіби аудармашысыз. Төмендегі сөйлемді English тіліне аударыңыз.",
|
| 60 |
+
"prefix": "<src=kk><tgt=en>"
|
| 61 |
+
},
|
| 62 |
+
"Kazakh to Russian": {
|
| 63 |
+
"system": "Сіз кәсіби аудармашысыз. Төмендегі сөйлемді орыс тіліне аударыңыз.",
|
| 64 |
+
"prefix": "<src=kk><tgt=ru>"
|
| 65 |
+
},
|
| 66 |
+
"Russian to Kazakh": {
|
| 67 |
+
"system": "Вы профессиональный переводчик. Переведите следующее предложение на қазақ язык.",
|
| 68 |
+
"prefix": "<src=ru><tgt=kk>"
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
|
| 72 |
# Set the title and description
|
| 73 |
title = "Kazakh Language Model"
|
|
|
|
| 81 |
message: str,
|
| 82 |
history: List[Tuple[str, str]],
|
| 83 |
model: str = "gemma_3_800M_sft_v2_translation-kazparc_latest.gguf", # Set default model
|
| 84 |
+
direction: str = "English to Kazakh",
|
| 85 |
max_tokens: int = 64,
|
| 86 |
temperature: float = 0.7,
|
| 87 |
top_p: float = 0.95,
|
|
|
|
| 151 |
|
| 152 |
messages = BasicChatHistory()
|
| 153 |
|
| 154 |
+
# Add the chat history
|
| 155 |
+
for user_msg, assistant_msg in history:
|
| 156 |
+
full_user_msg = user_prefix + " " + user_msg
|
| 157 |
+
messages.add_message({"role": Roles.user, "content": full_user_msg})
|
| 158 |
+
messages.add_message({"role": Roles.assistant, "content": assistant_msg})
|
| 159 |
+
full_message = user_prefix + " " + message
|
| 160 |
|
| 161 |
# Get the response stream
|
| 162 |
stream = agent.get_chat_response(
|
| 163 |
+
full_message,
|
| 164 |
llm_sampling_settings=settings,
|
| 165 |
chat_history=messages,
|
| 166 |
returns_streaming_generator=True,
|
|
|
|
| 191 |
),
|
| 192 |
additional_inputs=[
|
| 193 |
gr.Dropdown(
|
| 194 |
+
choices=["English to Kazakh", "Kazakh to English", "Kazakh to Russian", "Russian to Kazakh"],
|
| 195 |
+
label="Translation Direction",
|
| 196 |
+
info="Select the direction of translation"
|
|
|
|
|
|
|
|
|
|
| 197 |
),
|
| 198 |
gr.Textbox(
|
| 199 |
value="You are a helpful assistant.",
|