basantyahya commited on
Commit
573431c
·
verified ·
1 Parent(s): 571fa01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -10
app.py CHANGED
@@ -5,7 +5,12 @@ import os
5
  # -------------------------
6
  # Groq Client
7
  # -------------------------
8
- client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
 
 
 
 
 
9
 
10
  SYSTEM_PROMPT = """You are an expert in storyboarding.
11
  Provide structured, creative, and insightful responses about creating and refining storyboards.
@@ -13,18 +18,26 @@ Use clear sections, shots, and visual descriptions when possible.
13
  """
14
 
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
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
23
 
24
- for user, assistant in history:
25
- messages.append({"role": "user", "content": user})
26
- messages.append({"role": "assistant", "content": assistant})
27
 
 
28
  messages.append({"role": "user", "content": message})
29
 
30
  try:
@@ -37,13 +50,17 @@ def respond(message, history, model, temperature, max_tokens):
37
 
38
  assistant_reply = response.choices[0].message.content
39
 
40
- history.append((message, assistant_reply))
 
 
 
41
  return history
42
 
43
  except Exception as e:
44
- history.append((message, f"❌ Error: {str(e)}"))
45
  return history
46
 
 
47
  # -------------------------
48
  # Custom CSS
49
  # -------------------------
@@ -114,7 +131,7 @@ with gr.Blocks(css=custom_css) as demo:
114
  ex3 = gr.Button("📚 Romantic Bookstore Meet-Cute")
115
 
116
  # -------------------------
117
- # Interactions (FIXED)
118
  # -------------------------
119
  send.click(
120
  respond,
@@ -138,4 +155,5 @@ with gr.Blocks(css=custom_css) as demo:
138
  # Launch
139
  # -------------------------
140
  if __name__ == "__main__":
141
- demo.launch()
 
 
5
  # -------------------------
6
  # Groq Client
7
  # -------------------------
8
+ API_KEY = os.getenv("GROQ_API_KEY")
9
+
10
+ if not API_KEY:
11
+ raise RuntimeError("❌ Please set GROQ_API_KEY in your environment variables.")
12
+
13
+ client = Groq(api_key=API_KEY)
14
 
15
  SYSTEM_PROMPT = """You are an expert in storyboarding.
16
  Provide structured, creative, and insightful responses about creating and refining storyboards.
 
18
  """
19
 
20
  # -------------------------
21
+ # Chat Function (UPDATED)
22
  # -------------------------
23
  def respond(message, history, model, temperature, max_tokens):
24
+
25
+ if message is None:
26
+ message = ""
27
+
28
+ message = message.strip()
29
+
30
+ if message == "":
31
  return history
32
 
33
+ # Start with system prompt
34
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
35
 
36
+ # Append previous conversation (NEW FORMAT)
37
+ for msg in history:
38
+ messages.append(msg)
39
 
40
+ # Add new user message
41
  messages.append({"role": "user", "content": message})
42
 
43
  try:
 
50
 
51
  assistant_reply = response.choices[0].message.content
52
 
53
+ # Update history in NEW format
54
+ history.append({"role": "user", "content": message})
55
+ history.append({"role": "assistant", "content": assistant_reply})
56
+
57
  return history
58
 
59
  except Exception as e:
60
+ history.append({"role": "assistant", "content": f"❌ Error: {str(e)}"})
61
  return history
62
 
63
+
64
  # -------------------------
65
  # Custom CSS
66
  # -------------------------
 
131
  ex3 = gr.Button("📚 Romantic Bookstore Meet-Cute")
132
 
133
  # -------------------------
134
+ # Interactions
135
  # -------------------------
136
  send.click(
137
  respond,
 
155
  # Launch
156
  # -------------------------
157
  if __name__ == "__main__":
158
+ demo.queue().launch()
159
+