Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ def infer(message, history, enable_history=False, max_new_tokens=512):
|
|
| 29 |
)
|
| 30 |
model.eval()
|
| 31 |
|
| 32 |
-
#
|
| 33 |
if enable_history and history:
|
| 34 |
prev = "\n".join(
|
| 35 |
[f"User: {h[0]}\nGamunu: {h[1]}" for h in history if h[1] is not None]
|
|
@@ -63,66 +63,19 @@ with gr.Blocks() as demo:
|
|
| 63 |
enable_history = gr.Checkbox(label="Enable chat history", value=False)
|
| 64 |
max_new_tokens = gr.Slider(64, 1024, value=512, step=32, label="🔢 Max New Tokens")
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
gr.Markdown("### 🧩 Try an Example")
|
| 68 |
-
|
| 69 |
-
example_categories = {
|
| 70 |
-
"🧮 Maths & Logic": [
|
| 71 |
-
"රු. 250 කින් මිලදී ගත් දේ රු. 400 නම් එය ප්රතිශතයකින් කීයද වැඩි වී ඇත?",
|
| 72 |
-
"සාමාන්ය ප්රවණතාවය (mean) ගණනය කරන්නේ කෙසේද?",
|
| 73 |
-
"මීටර් 5 දිගක ලී දණ්ඩක් කොටස් 1.25 මීටර් දිග කොටස් 4කට බෙදන්න. කොපමණ දිගක් ඉතිරි වේද?",
|
| 74 |
-
],
|
| 75 |
-
"🌿 Science & Environment": [
|
| 76 |
-
"පෘථිවියේ වායු මණ්ඩලය ස්තර 5ක් ලෙස වෙන් වේ. ඒවා නම් කරන්න.",
|
| 77 |
-
"ෆොටෝසින්තසිස් ක්රියාවලිය පැහැදිලි කරන්න.",
|
| 78 |
-
"පරිසර පද්ධතියක් යනු කුමක්ද? උදාහරණයක් දෙන්න.",
|
| 79 |
-
],
|
| 80 |
-
"🎭 Roleplay / Creative": [
|
| 81 |
-
"ඔබ ගුරුවරයෙකු ලෙස ක්රියාකරන්න. ශිෂ්යයාට ඉතිහාසය උගන්වන්න.",
|
| 82 |
-
"ඔබ වෛද්යවරයෙකු ලෙස ක්රියාකරන්න. රෝගියෙකුට උණක් ඇති විට උපදෙස් දෙන්න.",
|
| 83 |
-
"ඔබ කවියෙකු ලෙස 'ගඟක්' ගැන කෙටි කවියක් ලියන්න.",
|
| 84 |
-
],
|
| 85 |
-
"🧠 Reasoning / Dependalism": [
|
| 86 |
-
"මිනිස් සමාජය තනිවම නොව යෙදුණු බව පැහැදිලි කරන්න.",
|
| 87 |
-
"අපි අන් අය මත රඳා පවතින ආකාරය උදාහරණ සමග පැහැදිලි කරන්න.",
|
| 88 |
-
"පරිසරය හා ආර්ථිකය අතර සම්බන්ධය විස්තර කරන්න.",
|
| 89 |
-
],
|
| 90 |
-
"🗣 Language / NLP": [
|
| 91 |
-
"මෙම වාක්යය සිංහලයට පරිවර්තනය කරන්න: 'The sun rises in the east.'",
|
| 92 |
-
"වචන 'ආදරය' සඳහා පරිවර්තන 3ක් දෙන්න.",
|
| 93 |
-
"වචනයක් එකක් අරගෙන එයට අදාළ විරුද්ධ පදයක් කියන්න.",
|
| 94 |
-
],
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
category_dropdown = gr.Dropdown(
|
| 98 |
-
label="Choose a Category",
|
| 99 |
-
choices=list(example_categories.keys()),
|
| 100 |
-
value="🧮 Maths & Logic",
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
example_dropdown = gr.Dropdown(
|
| 104 |
-
label="Select Example",
|
| 105 |
-
choices=example_categories["🧮 Maths & Logic"],
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
def update_examples(category):
|
| 109 |
-
return gr.update(choices=example_categories[category], value=example_categories[category][0])
|
| 110 |
-
|
| 111 |
-
category_dropdown.change(update_examples, inputs=category_dropdown, outputs=example_dropdown)
|
| 112 |
-
|
| 113 |
chat = gr.ChatInterface(
|
| 114 |
fn=lambda message, history: infer(message, history, enable_history.value, max_new_tokens.value),
|
| 115 |
title="Gamunu 4B Instruct Alpha",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
)
|
| 117 |
|
| 118 |
-
# Button to load example into chat input
|
| 119 |
-
def load_example(example):
|
| 120 |
-
return gr.update(value=example)
|
| 121 |
-
|
| 122 |
-
load_btn = gr.Button("📥 Load Example into Chat")
|
| 123 |
-
chat_textbox = chat.textbox # the message input in ChatInterface
|
| 124 |
-
load_btn.click(load_example, inputs=example_dropdown, outputs=chat_textbox)
|
| 125 |
-
|
| 126 |
gr.Markdown("""
|
| 127 |
---
|
| 128 |
🪶 **Model:** [`manthilaffs/Gamunu-4B-Instruct-Alpha`](https://huggingface.co/manthilaffs/Gamunu-4B-Instruct-Alpha)
|
|
|
|
| 29 |
)
|
| 30 |
model.eval()
|
| 31 |
|
| 32 |
+
# Add history only if enabled
|
| 33 |
if enable_history and history:
|
| 34 |
prev = "\n".join(
|
| 35 |
[f"User: {h[0]}\nGamunu: {h[1]}" for h in history if h[1] is not None]
|
|
|
|
| 63 |
enable_history = gr.Checkbox(label="Enable chat history", value=False)
|
| 64 |
max_new_tokens = gr.Slider(64, 1024, value=512, step=32, label="🔢 Max New Tokens")
|
| 65 |
|
| 66 |
+
# Use only stable arguments (compatible everywhere)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
chat = gr.ChatInterface(
|
| 68 |
fn=lambda message, history: infer(message, history, enable_history.value, max_new_tokens.value),
|
| 69 |
title="Gamunu 4B Instruct Alpha",
|
| 70 |
+
examples=[
|
| 71 |
+
["ෆොටෝසින්තසිස් ක්රියාවලිය පැහැදිලි කරන්න."],
|
| 72 |
+
["මෙම වාක්යය සිංහලයට පරිවර්තනය කරන්න: 'The sun rises in the east.'"],
|
| 73 |
+
["රු. 250 කින් මිලදී ගත් දේ රු. 400 නම් එය ප්රතිශතයකින් කීයද වැඩි වී ඇත?"],
|
| 74 |
+
["ඔබ ගුරුවරයෙකු ලෙස ක්රියාකරන්න. ශිෂ්යයාට ඉතිහාසය උගන්වන්න."],
|
| 75 |
+
["ඔබ කවියෙකු ලෙස 'ගඟක්' ගැන කෙටි කවියක් ලියන්න."],
|
| 76 |
+
]
|
| 77 |
)
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
gr.Markdown("""
|
| 80 |
---
|
| 81 |
🪶 **Model:** [`manthilaffs/Gamunu-4B-Instruct-Alpha`](https://huggingface.co/manthilaffs/Gamunu-4B-Instruct-Alpha)
|