Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,39 +15,37 @@ Use clear sections, shots, and visual descriptions when possible.
|
|
| 15 |
# -------------------------
|
| 16 |
# Chat Function (FIXED)
|
| 17 |
# -------------------------
|
| 18 |
-
def respond(message,
|
| 19 |
-
if not message or message.strip() == "":
|
| 20 |
-
|
| 21 |
|
| 22 |
# Start conversation with system prompt
|
| 23 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 24 |
|
| 25 |
# Add previous chat history (already dict-based)
|
| 26 |
-
for msg in history:
|
| 27 |
-
|
| 28 |
|
| 29 |
# Add new user message
|
| 30 |
messages.append({"role": "user", "content": message})
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
history.append({"role": "assistant", "content": f"❌ Error: {str(e)}"})
|
| 50 |
-
return history
|
| 51 |
|
| 52 |
# -------------------------
|
| 53 |
# Custom CSS
|
|
@@ -123,21 +121,21 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 123 |
# -------------------------
|
| 124 |
send.click(
|
| 125 |
respond,
|
| 126 |
-
inputs=[msg,
|
| 127 |
outputs=chatbot,
|
| 128 |
)
|
| 129 |
|
| 130 |
-
msg.submit(
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
)
|
| 135 |
|
| 136 |
-
clear.click(lambda: [], None, chatbot)
|
| 137 |
|
| 138 |
-
ex1.click(lambda: "Create a storyboard for a 30-second coffee commercial", None, msg)
|
| 139 |
-
ex2.click(lambda: "Generate a horror movie opening scene storyboard", None, msg)
|
| 140 |
-
ex3.click(lambda: "Design a storyboard for a romantic comedy meet-cute at a bookstore", None, msg)
|
| 141 |
|
| 142 |
# -------------------------
|
| 143 |
# Launch
|
|
|
|
| 15 |
# -------------------------
|
| 16 |
# Chat Function (FIXED)
|
| 17 |
# -------------------------
|
| 18 |
+
def respond(message, model, temperature, max_tokens):
|
| 19 |
+
# if not message or message.strip() == "":
|
| 20 |
+
# return history
|
| 21 |
|
| 22 |
# Start conversation with system prompt
|
| 23 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 24 |
|
| 25 |
# Add previous chat history (already dict-based)
|
| 26 |
+
# for msg in history:
|
| 27 |
+
# messages.append(msg)
|
| 28 |
|
| 29 |
# Add new user message
|
| 30 |
messages.append({"role": "user", "content": message})
|
| 31 |
|
| 32 |
+
|
| 33 |
+
response = client.chat.completions.create(
|
| 34 |
+
model=model,
|
| 35 |
+
messages=messages,
|
| 36 |
+
temperature=temperature,
|
| 37 |
+
max_completion_tokens=max_tokens,
|
| 38 |
+
)
|
| 39 |
|
| 40 |
+
assistant_reply = response.choices[0].message.content
|
| 41 |
|
| 42 |
+
# Update history in NEW format
|
| 43 |
+
# history.append({"role": "user", "content": message})
|
| 44 |
+
# history.append({"role": "assistant", "content": assistant_reply})
|
| 45 |
|
| 46 |
+
return assistant_reply
|
| 47 |
|
| 48 |
+
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# -------------------------
|
| 51 |
# Custom CSS
|
|
|
|
| 121 |
# -------------------------
|
| 122 |
send.click(
|
| 123 |
respond,
|
| 124 |
+
inputs=[msg, model, temperature, max_tokens],
|
| 125 |
outputs=chatbot,
|
| 126 |
)
|
| 127 |
|
| 128 |
+
# msg.submit(
|
| 129 |
+
# respond,
|
| 130 |
+
# inputs=[msg, chatbot, model, temperature, max_tokens],
|
| 131 |
+
# outputs=chatbot,
|
| 132 |
+
# )
|
| 133 |
|
| 134 |
+
# clear.click(lambda: [], None, chatbot)
|
| 135 |
|
| 136 |
+
# ex1.click(lambda: "Create a storyboard for a 30-second coffee commercial", None, msg)
|
| 137 |
+
# ex2.click(lambda: "Generate a horror movie opening scene storyboard", None, msg)
|
| 138 |
+
# ex3.click(lambda: "Design a storyboard for a romantic comedy meet-cute at a bookstore", None, msg)
|
| 139 |
|
| 140 |
# -------------------------
|
| 141 |
# Launch
|