basantyahya commited on
Commit
a67e8a4
·
verified ·
1 Parent(s): bcb7ed7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -15,16 +15,16 @@ Use clear sections, shots, and visual descriptions when possible.
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})
@@ -39,9 +39,9 @@ def respond(message, model, temperature, max_tokens):
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
 
@@ -121,21 +121,21 @@ with gr.Blocks(css=custom_css) as demo:
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
 
15
  # -------------------------
16
  # Chat Function (FIXED)
17
  # -------------------------
18
+ def respond(message,history , 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})
 
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
 
 
121
  # -------------------------
122
  send.click(
123
  respond,
124
+ inputs=[msg, chatbot ,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