basantyahya commited on
Commit
a76d728
·
verified ·
1 Parent(s): 43fc8cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -47
app.py CHANGED
@@ -2,21 +2,29 @@ import gradio as gr
2
  from groq import Groq
3
  import os
4
 
 
 
 
5
  client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
6
 
7
- SYSTEM_PROMPT = """You are an expert in storyboarding. Provide structured and insightful responses to queries
8
- about creating and refining storyboards"""
 
 
9
 
 
 
 
10
  def respond(message, history, model, temperature, max_tokens):
11
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
12
-
13
  for h in history:
14
  messages.append({"role": "user", "content": h[0]})
15
  if h[1]:
16
  messages.append({"role": "assistant", "content": h[1]})
17
-
18
  messages.append({"role": "user", "content": message})
19
-
20
  try:
21
  response = client.chat.completions.create(
22
  model=model,
@@ -25,48 +33,104 @@ def respond(message, history, model, temperature, max_tokens):
25
  max_completion_tokens=max_tokens,
26
  )
27
  return response.choices[0].message.content
 
28
  except Exception as e:
29
- return f"Error: {str(e)}"
30
-
31
- # ChatInterface with additional inputs for parameters
32
- demo = gr.ChatInterface(
33
- fn=respond,
34
- title=" The Magical Storyboard ^O^",
35
- description="Create your storyboards to simulate your imagination by only one click!",
36
- additional_inputs=[
37
- gr.Dropdown(
38
- choices=[
39
- "llama-3.3-70b-versatile",
40
- "llama-3.1-8b-instant",
41
- ],
42
- value="llama-3.3-70b-versatile",
43
- label="Model",
44
- info="Select the AI model to use"
45
- ),
46
- gr.Slider(
47
- minimum=0,
48
- maximum=2,
49
- value=0.9,
50
- step=0.1,
51
- label="Temperature",
52
- info="Controls randomness. Lower = more focused, Higher = more creative"
53
- ),
54
- gr.Slider(
55
- minimum=256,
56
- maximum=8192,
57
- value=2048,
58
- step=256,
59
- label="Max Tokens",
60
- info="Maximum length of the response"
61
- ),
62
- ],
63
- examples=[
64
- ["Create a storyboard for a 30-second coffee commercial"],
65
- ["Generate a horror movie opening scene storyboard"],
66
- ["Design a storyboard for a romantic comedy meet-cute at a bookstore"],
67
- ],
68
-
69
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
 
 
 
71
  if __name__ == "__main__":
72
- demo.launch()
 
2
  from groq import Groq
3
  import os
4
 
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.
12
+ Use clear sections, shots, and visual descriptions when possible.
13
+ """
14
 
15
+ # -------------------------
16
+ # Chat Function
17
+ # -------------------------
18
  def respond(message, history, model, temperature, max_tokens):
19
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
20
+
21
  for h in history:
22
  messages.append({"role": "user", "content": h[0]})
23
  if h[1]:
24
  messages.append({"role": "assistant", "content": h[1]})
25
+
26
  messages.append({"role": "user", "content": message})
27
+
28
  try:
29
  response = client.chat.completions.create(
30
  model=model,
 
33
  max_completion_tokens=max_tokens,
34
  )
35
  return response.choices[0].message.content
36
+
37
  except Exception as e:
38
+ return f"Error: {str(e)}"
39
+
40
+ # -------------------------
41
+ # Custom CSS
42
+ # -------------------------
43
+ custom_css = """
44
+ body {
45
+ background: linear-gradient(135deg, #0f172a, #1e293b);
46
+ }
47
+
48
+ #title {
49
+ text-align: center;
50
+ font-size: 32px;
51
+ font-weight: bold;
52
+ color: #fbbf24;
53
+ }
54
+
55
+ #subtitle {
56
+ text-align: center;
57
+ font-size: 16px;
58
+ color: #e5e7eb;
59
+ }
60
+ """
61
+
62
+ # -------------------------
63
+ # UI
64
+ # -------------------------
65
+ with gr.Blocks(css=custom_css) as demo:
66
+
67
+ gr.Markdown(" 🎨 ⚡ The Magical Storyboard ⚡ 🎬 ^O^", elem_id="title")
68
+ gr.Markdown(
69
+ "Turn your imagination into **cinematic storyboards** using AI — one prompt at a time.",
70
+ elem_id="subtitle",
71
+ )
72
+
73
+ with gr.Row():
74
+ with gr.Column(scale=3):
75
+ chatbot = gr.Chatbot(height=420)
76
+ msg = gr.Textbox(
77
+ placeholder="Describe your scene, commercial, or movie moment...",
78
+ label="Your Idea"
79
+ )
80
+
81
+ send = gr.Button("🎥 Create Storyboard")
82
+ clear = gr.Button("🧹 Clear Chat")
83
+
84
+ with gr.Column(scale=1):
85
+ gr.Markdown("### ⚙️ Controls")
86
+
87
+ model = gr.Dropdown(
88
+ choices=[
89
+ "llama-3.3-70b-versatile",
90
+ "llama-3.1-8b-instant",
91
+ ],
92
+ value="llama-3.3-70b-versatile",
93
+ label="Model",
94
+ )
95
+
96
+ temperature = gr.Slider(
97
+ 0, 2, value=0.9, step=0.1,
98
+ label="Creativity (Temperature)"
99
+ )
100
+
101
+ max_tokens = gr.Slider(
102
+ 256, 8192, value=2048, step=256,
103
+ label="Max Tokens"
104
+ )
105
+
106
+ gr.Markdown("### ✨ Examples")
107
+ ex1 = gr.Button("☕ 30s Coffee Commercial")
108
+ ex2 = gr.Button("👻 Horror Movie Opening")
109
+ ex3 = gr.Button("📚 Romantic Bookstore Meet-Cute")
110
+
111
+ # -------------------------
112
+ # Interactions
113
+ # -------------------------
114
+ send.click(
115
+ respond,
116
+ inputs=[msg, chatbot, model, temperature, max_tokens],
117
+ outputs=chatbot,
118
+ )
119
+
120
+ msg.submit(
121
+ respond,
122
+ inputs=[msg, chatbot, model, temperature, max_tokens],
123
+ outputs=chatbot,
124
+ )
125
+
126
+ clear.click(lambda: [], None, chatbot)
127
+
128
+ ex1.click(lambda: "Create a storyboard for a 30-second coffee commercial", None, msg)
129
+ ex2.click(lambda: "Generate a horror movie opening scene storyboard", None, msg)
130
+ ex3.click(lambda: "Design a storyboard for a romantic comedy meet-cute at a bookstore", None, msg)
131
 
132
+ # -------------------------
133
+ # Launch
134
+ # -------------------------
135
  if __name__ == "__main__":
136
+ demo.launch()