Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,7 +46,7 @@ def chat_fn(message, history, mode="Normal Chat", model=DEFAULT_MODEL, image=Non
|
|
| 46 |
try:
|
| 47 |
messages = [{"role": "system", "content": MODE_PROMPTS.get(mode, MODE_PROMPTS["Normal Chat"])}]
|
| 48 |
|
| 49 |
-
# SAFELY process history
|
| 50 |
for pair in history:
|
| 51 |
if isinstance(pair, list) and len(pair) == 2:
|
| 52 |
user_msg, assistant_msg = pair
|
|
@@ -75,7 +75,7 @@ def chat_fn(message, history, mode="Normal Chat", model=DEFAULT_MODEL, image=Non
|
|
| 75 |
return f"⚠️ Error: {str(e)}"
|
| 76 |
|
| 77 |
# =========================
|
| 78 |
-
# UI
|
| 79 |
# =========================
|
| 80 |
|
| 81 |
with gr.Blocks(title="🦙 NeoHelper — Eyad’s Groq-powered Assistant") as demo:
|
|
@@ -99,19 +99,35 @@ with gr.Blocks(title="🦙 NeoHelper — Eyad’s Groq-powered Assistant") as de
|
|
| 99 |
label="Model"
|
| 100 |
)
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
image_input = gr.Image(type="filepath", label="Upload Image (Optional)")
|
| 103 |
ascii_toggle = gr.Checkbox(label="Convert image to ASCII", value=False)
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
msg,
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
)
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
)
|
| 116 |
|
| 117 |
demo.launch()
|
|
|
|
| 46 |
try:
|
| 47 |
messages = [{"role": "system", "content": MODE_PROMPTS.get(mode, MODE_PROMPTS["Normal Chat"])}]
|
| 48 |
|
| 49 |
+
# SAFELY process history
|
| 50 |
for pair in history:
|
| 51 |
if isinstance(pair, list) and len(pair) == 2:
|
| 52 |
user_msg, assistant_msg = pair
|
|
|
|
| 75 |
return f"⚠️ Error: {str(e)}"
|
| 76 |
|
| 77 |
# =========================
|
| 78 |
+
# UI (FULLY FIXED)
|
| 79 |
# =========================
|
| 80 |
|
| 81 |
with gr.Blocks(title="🦙 NeoHelper — Eyad’s Groq-powered Assistant") as demo:
|
|
|
|
| 99 |
label="Model"
|
| 100 |
)
|
| 101 |
|
| 102 |
+
chatbot = gr.Chatbot(height=500)
|
| 103 |
+
|
| 104 |
+
with gr.Row():
|
| 105 |
+
user_input = gr.Textbox(
|
| 106 |
+
placeholder="Type your message…",
|
| 107 |
+
show_label=False,
|
| 108 |
+
lines=2
|
| 109 |
+
)
|
| 110 |
+
send_btn = gr.Button("Send")
|
| 111 |
+
|
| 112 |
image_input = gr.Image(type="filepath", label="Upload Image (Optional)")
|
| 113 |
ascii_toggle = gr.Checkbox(label="Convert image to ASCII", value=False)
|
| 114 |
|
| 115 |
+
def on_send(msg, history, mode, model, image, include_ascii):
|
| 116 |
+
reply = chat_fn(
|
| 117 |
msg,
|
| 118 |
+
history,
|
| 119 |
+
mode,
|
| 120 |
+
model,
|
| 121 |
+
image,
|
| 122 |
+
include_ascii
|
| 123 |
+
)
|
| 124 |
+
history.append([msg, reply])
|
| 125 |
+
return history, ""
|
| 126 |
+
|
| 127 |
+
send_btn.click(
|
| 128 |
+
on_send,
|
| 129 |
+
inputs=[user_input, chatbot, mode_dd, model_dd, image_input, ascii_toggle],
|
| 130 |
+
outputs=[chatbot, user_input]
|
| 131 |
)
|
| 132 |
|
| 133 |
demo.launch()
|