Fix system prompt input bug into generate(), and add translations of interface
Browse files
app.py
CHANGED
@@ -12,9 +12,11 @@ DEFAULT_MAX_NEW_TOKENS = 512
|
|
12 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
13 |
|
14 |
DESCRIPTION = """\
|
15 |
-
#
|
16 |
|
17 |
-
|
|
|
|
|
18 |
"""
|
19 |
|
20 |
LICENSE = """
|
@@ -44,7 +46,6 @@ if torch.cuda.is_available():
|
|
44 |
def generate(
|
45 |
message: str,
|
46 |
chat_history: list[tuple[str, str]],
|
47 |
-
system_prompt: str = SYSTEM_PROMPT,
|
48 |
max_new_tokens: int = 1024,
|
49 |
temperature: float = 0.6,
|
50 |
top_p: float = 0.9,
|
@@ -52,9 +53,7 @@ def generate(
|
|
52 |
repetition_penalty: float = 1.2,
|
53 |
) -> Iterator[str]:
|
54 |
print("chat history: ", chat_history)
|
55 |
-
conversation = []
|
56 |
-
if system_prompt:
|
57 |
-
conversation.append({"role": "system", "content": system_prompt})
|
58 |
for user, assistant in chat_history:
|
59 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
60 |
conversation.append({"role": "user", "content": message})
|
@@ -94,62 +93,12 @@ examples = [
|
|
94 |
["Nivae nini kwenye harusi?"],
|
95 |
]
|
96 |
|
97 |
-
# chat_interface = gr.ChatInterface(
|
98 |
-
# fn=generate,
|
99 |
-
# additional_inputs=[
|
100 |
-
# gr.Textbox(label="System prompt", lines=6),
|
101 |
-
# gr.Slider(
|
102 |
-
# label="Max new tokens",
|
103 |
-
# minimum=1,
|
104 |
-
# maximum=MAX_MAX_NEW_TOKENS,
|
105 |
-
# step=1,
|
106 |
-
# value=DEFAULT_MAX_NEW_TOKENS,
|
107 |
-
# ),
|
108 |
-
# gr.Slider(
|
109 |
-
# label="Temperature",
|
110 |
-
# minimum=0.1,
|
111 |
-
# maximum=4.0,
|
112 |
-
# step=0.1,
|
113 |
-
# value=0.6,
|
114 |
-
# ),
|
115 |
-
# gr.Slider(
|
116 |
-
# label="Top-p (nucleus sampling)",
|
117 |
-
# minimum=0.05,
|
118 |
-
# maximum=1.0,
|
119 |
-
# step=0.05,
|
120 |
-
# value=0.9,
|
121 |
-
# ),
|
122 |
-
# gr.Slider(
|
123 |
-
# label="Top-k",
|
124 |
-
# minimum=1,
|
125 |
-
# maximum=1000,
|
126 |
-
# step=1,
|
127 |
-
# value=50,
|
128 |
-
# ),
|
129 |
-
# gr.Slider(
|
130 |
-
# label="Repetition penalty",
|
131 |
-
# minimum=1.0,
|
132 |
-
# maximum=2.0,
|
133 |
-
# step=0.05,
|
134 |
-
# value=1.2,
|
135 |
-
# ),
|
136 |
-
# ],
|
137 |
-
# stop_btn=None,
|
138 |
-
# examples=[
|
139 |
-
# ["Ninawezaje kupata usingizi haraka?"],
|
140 |
-
# ["Bosi wangu anadhibiti sana, nifanye nini?"],
|
141 |
-
# ["Je, ni vipindi gani muhimu katika historia vya kujua kuvihusu?"],
|
142 |
-
# ["Ni kazi gani nzuri ikiwa ninataka kupata pesa lakini pia kufurahiya?"],
|
143 |
-
# ["Nivae nini kwenye harusi?"],
|
144 |
-
# ],
|
145 |
-
# )
|
146 |
-
|
147 |
with gr.Blocks(css="style.css") as demo:
|
148 |
gr.Markdown(DESCRIPTION)
|
149 |
chatbot = gr.Chatbot()
|
150 |
-
msg = gr.Textbox(label="Enter your message")
|
151 |
-
submit_btn = gr.Button("Submit")
|
152 |
-
clear = gr.Button("Clear")
|
153 |
|
154 |
def user(user_message, history):
|
155 |
return "", history + [[user_message, None]]
|
@@ -163,9 +112,9 @@ with gr.Blocks(css="style.css") as demo:
|
|
163 |
history[-1][1] = bot_message
|
164 |
yield history
|
165 |
|
166 |
-
gr.Examples(examples=examples, inputs=[msg], label="Examples")
|
167 |
|
168 |
-
with gr.Accordion("Advanced Options", open=False):
|
169 |
max_new_tokens = gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS)
|
170 |
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, step=0.1, value=0.6)
|
171 |
top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9)
|
|
|
12 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
13 |
|
14 |
DESCRIPTION = """\
|
15 |
+
# Msaidizi wa AI ya Kiswahili
|
16 |
|
17 |
+
Hii inaonyesha kielelezo cha Kiswahili (Jacaranda) kilichoundwa kutoka Llama-2 7b, kinachotumiwa kama msaidizi wa AI kwa maisha ya kila siku.
|
18 |
+
|
19 |
+
(This Space demonstrates the [Swahili (Jacaranda) model](https://huggingface.co/abhinand/tamil-llama-7b-instruct-v0.1) fine-tuned from Llama-2 7b, used as a daily life AI assistant.)
|
20 |
"""
|
21 |
|
22 |
LICENSE = """
|
|
|
46 |
def generate(
|
47 |
message: str,
|
48 |
chat_history: list[tuple[str, str]],
|
|
|
49 |
max_new_tokens: int = 1024,
|
50 |
temperature: float = 0.6,
|
51 |
top_p: float = 0.9,
|
|
|
53 |
repetition_penalty: float = 1.2,
|
54 |
) -> Iterator[str]:
|
55 |
print("chat history: ", chat_history)
|
56 |
+
conversation = [{"role": "system", "content": SYSTEM_PROMPT}]
|
|
|
|
|
57 |
for user, assistant in chat_history:
|
58 |
conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
59 |
conversation.append({"role": "user", "content": message})
|
|
|
93 |
["Nivae nini kwenye harusi?"],
|
94 |
]
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
with gr.Blocks(css="style.css") as demo:
|
97 |
gr.Markdown(DESCRIPTION)
|
98 |
chatbot = gr.Chatbot()
|
99 |
+
msg = gr.Textbox(label="Ingiza ujumbe wako / Enter your message")
|
100 |
+
submit_btn = gr.Button("Wasilisha / Submit")
|
101 |
+
clear = gr.Button("Wazi / Clear")
|
102 |
|
103 |
def user(user_message, history):
|
104 |
return "", history + [[user_message, None]]
|
|
|
112 |
history[-1][1] = bot_message
|
113 |
yield history
|
114 |
|
115 |
+
gr.Examples(examples=examples, inputs=[msg], label="Mifano / Examples")
|
116 |
|
117 |
+
with gr.Accordion("Chaguzi za Juu / Advanced Options", open=False):
|
118 |
max_new_tokens = gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS)
|
119 |
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, step=0.1, value=0.6)
|
120 |
top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9)
|