Spaces:
Running
on
Zero
Running
on
Zero
idan shenfeld
commited on
Commit
·
5a9e88a
1
Parent(s):
5b93962
load languages from json
Browse files- app/app.py +11 -7
- app/languages.json +14 -0
app/app.py
CHANGED
@@ -6,6 +6,7 @@ from datetime import datetime
|
|
6 |
from mimetypes import guess_type
|
7 |
from pathlib import Path
|
8 |
from typing import Optional
|
|
|
9 |
|
10 |
import spaces
|
11 |
import gradio as gr
|
@@ -89,15 +90,14 @@ def add_user_message(history, message):
|
|
89 |
|
90 |
|
91 |
def format_system_message(language: str, history: list):
|
92 |
-
if history:
|
93 |
-
if history[0]["role"] == "system":
|
94 |
-
history = history[1:]
|
95 |
system_message = [
|
96 |
{
|
97 |
"role": "system",
|
98 |
-
"content": LANGUAGES[
|
99 |
}
|
100 |
]
|
|
|
|
|
101 |
history = system_message + history
|
102 |
return history
|
103 |
|
@@ -553,10 +553,14 @@ with gr.Blocks(css=css) as demo:
|
|
553 |
outputs=[conversation_id],
|
554 |
)
|
555 |
|
|
|
|
|
|
|
|
|
556 |
demo.load(
|
557 |
-
|
558 |
-
inputs=
|
559 |
-
outputs=
|
560 |
)
|
561 |
|
562 |
demo.launch()
|
|
|
6 |
from mimetypes import guess_type
|
7 |
from pathlib import Path
|
8 |
from typing import Optional
|
9 |
+
import json
|
10 |
|
11 |
import spaces
|
12 |
import gradio as gr
|
|
|
90 |
|
91 |
|
92 |
def format_system_message(language: str, history: list):
|
|
|
|
|
|
|
93 |
system_message = [
|
94 |
{
|
95 |
"role": "system",
|
96 |
+
"content": LANGUAGES.get(language, LANGUAGES["English"]),
|
97 |
}
|
98 |
]
|
99 |
+
if history and history[0]["role"] == "system":
|
100 |
+
history = history[1:]
|
101 |
history = system_message + history
|
102 |
return history
|
103 |
|
|
|
553 |
outputs=[conversation_id],
|
554 |
)
|
555 |
|
556 |
+
def on_app_load():
|
557 |
+
update_language_clients()
|
558 |
+
return str(uuid.uuid4())
|
559 |
+
|
560 |
demo.load(
|
561 |
+
fn=on_app_load,
|
562 |
+
inputs=None,
|
563 |
+
outputs=session_id
|
564 |
)
|
565 |
|
566 |
demo.launch()
|
app/languages.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"English": "You are a helpful assistant. Always respond to requests in fluent and natural English, regardless of the language used by the user.",
|
3 |
+
"Dutch": "Je bent een behulpzame assistent die uitsluitend in het Nederlands communiceert. Beantwoord alle vragen en verzoeken in vloeiend en natuurlijk Nederlands, ongeacht de taal waarin de gebruiker schrijft.",
|
4 |
+
"Italian": "Sei un assistente utile e rispondi sempre in italiano in modo naturale e fluente, indipendentemente dalla lingua utilizzata dall'utente.",
|
5 |
+
"Spanish": "Eres un asistente útil que siempre responde en español de manera fluida y natural, independientemente del idioma utilizado por el usuario.",
|
6 |
+
"French": "Tu es un assistant utile qui répond toujours en français de manière fluide et naturelle, quelle que soit la langue utilisée par l'utilisateur.",
|
7 |
+
"German": "Du bist ein hilfreicher Assistent, der stets auf Deutsch in einer natürlichen und fließenden Weise antwortet, unabhängig von der Sprache des Benutzers.",
|
8 |
+
"Portuguese": "Você é um assistente útil que sempre responde em português de forma natural e fluente, independentemente do idioma utilizado pelo usuário.",
|
9 |
+
"Russian": "Ты полезный помощник, который всегда отвечает на русском языке плавно и естественно, независимо от языка пользователя.",
|
10 |
+
"Chinese": "你是一个有用的助手,总是用流畅自然的中文回答问题,无论用户使用哪种语言。",
|
11 |
+
"Japanese": "あなたは役に立つアシスタントであり、常に流暢で自然な日本語で応答します。ユーザーが使用する言語に関係なく、日本語で対応してください。",
|
12 |
+
"Korean": "당신은 유용한 도우미이며, 항상 유창하고 자연스러운 한국어로 응답합니다. 사용자가 어떤 언어를 사용하든 한국어로 대답하세요.",
|
13 |
+
"Hebrew": " אתה עוזר טוב ומועיל שמדבר בעברית ועונה בעברית."
|
14 |
+
}
|