Spaces:
Sleeping
Sleeping
fix: Gradio 6.0 compat - messages format, css/theme to launch(), dtype not torch_dtype
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ MODEL_ID = "reaperdoesntknow/DualMinded-Qwen3-1.7B"
|
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
MODEL_ID,
|
| 12 |
-
|
| 13 |
device_map="auto",
|
| 14 |
trust_remote_code=True,
|
| 15 |
)
|
|
@@ -41,11 +41,9 @@ def generate(
|
|
| 41 |
|
| 42 |
messages = [{"role": "system", "content": system_prompt}]
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
for
|
| 46 |
-
messages.append({"role": "
|
| 47 |
-
if assistant_msg:
|
| 48 |
-
messages.append({"role": "assistant", "content": assistant_msg})
|
| 49 |
|
| 50 |
messages.append({"role": "user", "content": message})
|
| 51 |
|
|
@@ -133,7 +131,7 @@ footer { display: none !important; }
|
|
| 133 |
"""
|
| 134 |
|
| 135 |
# --- UI ---
|
| 136 |
-
with gr.Blocks(
|
| 137 |
|
| 138 |
gr.HTML("""
|
| 139 |
<div class="main-header">
|
|
@@ -157,7 +155,6 @@ with gr.Blocks(css=css, theme=gr.themes.Base(primary_hue="teal", neutral_hue="sl
|
|
| 157 |
height=500,
|
| 158 |
show_label=False,
|
| 159 |
container=True,
|
| 160 |
-
type="tuples",
|
| 161 |
)
|
| 162 |
|
| 163 |
with gr.Row():
|
|
@@ -191,13 +188,14 @@ with gr.Blocks(css=css, theme=gr.themes.Base(primary_hue="teal", neutral_hue="sl
|
|
| 191 |
""")
|
| 192 |
|
| 193 |
def user_message(message, history):
|
| 194 |
-
|
|
|
|
| 195 |
|
| 196 |
def bot_response(history, system_prompt, max_tokens, temperature, top_p, rep_penalty):
|
| 197 |
-
user_msg = history[-1][
|
| 198 |
past = history[:-1]
|
| 199 |
response = generate(user_msg, past, system_prompt, max_tokens, temperature, top_p, rep_penalty)
|
| 200 |
-
history
|
| 201 |
return history
|
| 202 |
|
| 203 |
msg.submit(
|
|
@@ -212,4 +210,4 @@ with gr.Blocks(css=css, theme=gr.themes.Base(primary_hue="teal", neutral_hue="sl
|
|
| 212 |
bot_response, [chatbot, system_prompt, max_tokens, temperature, top_p, rep_penalty], chatbot
|
| 213 |
)
|
| 214 |
|
| 215 |
-
demo.launch()
|
|
|
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
MODEL_ID,
|
| 12 |
+
dtype=torch.bfloat16,
|
| 13 |
device_map="auto",
|
| 14 |
trust_remote_code=True,
|
| 15 |
)
|
|
|
|
| 41 |
|
| 42 |
messages = [{"role": "system", "content": system_prompt}]
|
| 43 |
|
| 44 |
+
# Gradio 6 messages format: list of {"role": ..., "content": ...}
|
| 45 |
+
for msg in history:
|
| 46 |
+
messages.append({"role": msg["role"], "content": msg["content"]})
|
|
|
|
|
|
|
| 47 |
|
| 48 |
messages.append({"role": "user", "content": message})
|
| 49 |
|
|
|
|
| 131 |
"""
|
| 132 |
|
| 133 |
# --- UI ---
|
| 134 |
+
with gr.Blocks() as demo:
|
| 135 |
|
| 136 |
gr.HTML("""
|
| 137 |
<div class="main-header">
|
|
|
|
| 155 |
height=500,
|
| 156 |
show_label=False,
|
| 157 |
container=True,
|
|
|
|
| 158 |
)
|
| 159 |
|
| 160 |
with gr.Row():
|
|
|
|
| 188 |
""")
|
| 189 |
|
| 190 |
def user_message(message, history):
|
| 191 |
+
history = history + [{"role": "user", "content": message}]
|
| 192 |
+
return "", history
|
| 193 |
|
| 194 |
def bot_response(history, system_prompt, max_tokens, temperature, top_p, rep_penalty):
|
| 195 |
+
user_msg = history[-1]["content"]
|
| 196 |
past = history[:-1]
|
| 197 |
response = generate(user_msg, past, system_prompt, max_tokens, temperature, top_p, rep_penalty)
|
| 198 |
+
history = history + [{"role": "assistant", "content": response}]
|
| 199 |
return history
|
| 200 |
|
| 201 |
msg.submit(
|
|
|
|
| 210 |
bot_response, [chatbot, system_prompt, max_tokens, temperature, top_p, rep_penalty], chatbot
|
| 211 |
)
|
| 212 |
|
| 213 |
+
demo.launch(css=css, theme=gr.themes.Base(primary_hue="teal", neutral_hue="slate"))
|