anaspro
commited on
Commit
·
aabc997
1
Parent(s):
94352d6
Simplify to single Shako v4 model only - remove model selection and use single model
Browse files
app.py
CHANGED
|
@@ -9,27 +9,19 @@ import spaces
|
|
| 9 |
import time
|
| 10 |
import os
|
| 11 |
|
| 12 |
-
# model config
|
| 13 |
-
|
| 14 |
-
model_4b_name = "anaspro/Shako-4B-it"
|
| 15 |
|
| 16 |
# Load token from environment if available
|
| 17 |
hf_token = os.getenv("HF_TOKEN")
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
device_map="auto",
|
| 22 |
torch_dtype=torch.bfloat16,
|
| 23 |
token=hf_token
|
| 24 |
).eval()
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
model_4b = Gemma3ForConditionalGeneration.from_pretrained(
|
| 28 |
-
model_4b_name,
|
| 29 |
-
device_map="auto",
|
| 30 |
-
torch_dtype=torch.bfloat16
|
| 31 |
-
).eval()
|
| 32 |
-
processor_4b = AutoProcessor.from_pretrained(model_4b_name)
|
| 33 |
# I will add timestamp later
|
| 34 |
def extract_video_frames(video_path, num_frames=8):
|
| 35 |
cap = cv2.VideoCapture(video_path)
|
|
@@ -92,7 +84,7 @@ def format_conversation_history(chat_history):
|
|
| 92 |
return messages
|
| 93 |
|
| 94 |
@spaces.GPU(duration=120)
|
| 95 |
-
def generate_response(input_data, chat_history,
|
| 96 |
if isinstance(input_data, dict) and "text" in input_data:
|
| 97 |
text = input_data["text"]
|
| 98 |
files = input_data.get("files", [])
|
|
@@ -109,12 +101,7 @@ def generate_response(input_data, chat_history, model_choice, max_new_tokens, sy
|
|
| 109 |
messages[-1]["content"].extend(new_message["content"])
|
| 110 |
else:
|
| 111 |
messages.append(new_message)
|
| 112 |
-
|
| 113 |
-
model = model_12b
|
| 114 |
-
processor = processor_12b
|
| 115 |
-
else:
|
| 116 |
-
model = model_4b
|
| 117 |
-
processor = processor_4b
|
| 118 |
inputs = processor.apply_chat_template(
|
| 119 |
messages,
|
| 120 |
add_generation_prompt=True,
|
|
@@ -144,11 +131,6 @@ def generate_response(input_data, chat_history, model_choice, max_new_tokens, sy
|
|
| 144 |
demo = gr.ChatInterface(
|
| 145 |
fn=generate_response,
|
| 146 |
additional_inputs=[
|
| 147 |
-
gr.Dropdown(
|
| 148 |
-
label="Model",
|
| 149 |
-
choices=["Gemma 3 12B", "Gemma 3 4B"],
|
| 150 |
-
value="Gemma 3 12B"
|
| 151 |
-
),
|
| 152 |
gr.Slider(label="Max new tokens", minimum=100, maximum=2000, step=1, value=512),
|
| 153 |
gr.Textbox(
|
| 154 |
label="System Prompt",
|
|
@@ -167,8 +149,8 @@ demo = gr.ChatInterface(
|
|
| 167 |
cache_examples=False,
|
| 168 |
type="messages",
|
| 169 |
description="""
|
| 170 |
-
#
|
| 171 |
-
|
| 172 |
""",
|
| 173 |
fill_height=True,
|
| 174 |
textbox=gr.MultimodalTextbox(
|
|
|
|
| 9 |
import time
|
| 10 |
import os
|
| 11 |
|
| 12 |
+
# model config - Single model: Shako v4
|
| 13 |
+
model_name = "anaspro/Shako-4B-it-v4"
|
|
|
|
| 14 |
|
| 15 |
# Load token from environment if available
|
| 16 |
hf_token = os.getenv("HF_TOKEN")
|
| 17 |
|
| 18 |
+
model = Gemma3ForConditionalGeneration.from_pretrained(
|
| 19 |
+
model_name,
|
| 20 |
device_map="auto",
|
| 21 |
torch_dtype=torch.bfloat16,
|
| 22 |
token=hf_token
|
| 23 |
).eval()
|
| 24 |
+
processor = AutoProcessor.from_pretrained(model_name, token=hf_token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# I will add timestamp later
|
| 26 |
def extract_video_frames(video_path, num_frames=8):
|
| 27 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
| 84 |
return messages
|
| 85 |
|
| 86 |
@spaces.GPU(duration=120)
|
| 87 |
+
def generate_response(input_data, chat_history, max_new_tokens, system_prompt, temperature, top_p, top_k, repetition_penalty):
|
| 88 |
if isinstance(input_data, dict) and "text" in input_data:
|
| 89 |
text = input_data["text"]
|
| 90 |
files = input_data.get("files", [])
|
|
|
|
| 101 |
messages[-1]["content"].extend(new_message["content"])
|
| 102 |
else:
|
| 103 |
messages.append(new_message)
|
| 104 |
+
# Use the single Shako v4 model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
inputs = processor.apply_chat_template(
|
| 106 |
messages,
|
| 107 |
add_generation_prompt=True,
|
|
|
|
| 131 |
demo = gr.ChatInterface(
|
| 132 |
fn=generate_response,
|
| 133 |
additional_inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
gr.Slider(label="Max new tokens", minimum=100, maximum=2000, step=1, value=512),
|
| 135 |
gr.Textbox(
|
| 136 |
label="System Prompt",
|
|
|
|
| 149 |
cache_examples=False,
|
| 150 |
type="messages",
|
| 151 |
description="""
|
| 152 |
+
# شكو - Shako Iraqi AI
|
| 153 |
+
نموذج ذكاء عراقي متقدم يتحدث بالعراقي، يدعم الصور والفيديوهات والمحادثات الصوتية.
|
| 154 |
""",
|
| 155 |
fill_height=True,
|
| 156 |
textbox=gr.MultimodalTextbox(
|