Rahatara commited on
Commit
324db76
ยท
verified ยท
1 Parent(s): 07de933

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -20
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  from groq import Groq
4
 
5
  # -----------------------------
6
- # Initialize Groq
7
  # -----------------------------
8
  client = Groq(api_key=os.getenv("GROQ_API_KEY"))
9
 
@@ -15,24 +15,24 @@ SYSTEM_PROMPT = (
15
  # -----------------------------
16
  # Chat function
17
  # -----------------------------
18
- def chat_with_bot(user_input, history):
19
  if history is None:
20
  history = []
21
 
22
  if not history:
23
  history.append({"role": "system", "content": SYSTEM_PROMPT})
24
 
25
- history.append({"role": "user", "content": user_input})
26
 
27
- completion = client.chat.completions.create(
28
  model="llama-3.3-70b-versatile",
29
  messages=history,
30
- max_tokens=512,
31
  temperature=1,
 
32
  )
33
 
34
- reply = completion.choices[0].message.content
35
- history.append({"role": "assistant", "content": reply})
36
 
37
  return history, history
38
 
@@ -44,7 +44,7 @@ def generate_storyboard(scenario):
44
  if not scenario.strip():
45
  return "Please enter a scenario."
46
 
47
- completion = client.chat.completions.create(
48
  model="llama-3.3-70b-versatile",
49
  messages=[
50
  {"role": "system", "content": "Generate a 6-scene storyboard in table format."},
@@ -53,11 +53,11 @@ def generate_storyboard(scenario):
53
  max_tokens=700,
54
  )
55
 
56
- return completion.choices[0].message.content
57
 
58
 
59
  # -----------------------------
60
- # UI
61
  # -----------------------------
62
  with gr.Blocks(title="Storyboard Assistant") as demo:
63
  gr.Markdown("## ๐Ÿ“– Storyboard Assistant")
@@ -68,26 +68,28 @@ with gr.Blocks(title="Storyboard Assistant") as demo:
68
  state = gr.State([])
69
 
70
  user_input = gr.Textbox(label="Your Message")
71
- send = gr.Button("Ask")
72
 
73
- send.click(
74
- chat_with_bot,
75
  inputs=[user_input, state],
76
  outputs=[chatbot, state],
77
  )
78
 
79
  with gr.Tab("๐Ÿ“– Generate Storyboard"):
80
  scenario = gr.Textbox(label="Scenario")
81
- generate = gr.Button("Generate")
82
  output = gr.Textbox(lines=12)
83
 
84
- generate.click(generate_storyboard, scenario, output)
 
 
 
 
85
 
86
 
87
  # -----------------------------
88
- # ๐Ÿšจ CRITICAL LAUNCH FIX
89
  # -----------------------------
90
- demo.launch(
91
- ssr=False, # โœ… disables schema bug
92
- show_api=False # โœ… prevents /api/info crash
93
- )
 
3
  from groq import Groq
4
 
5
  # -----------------------------
6
+ # Groq Client
7
  # -----------------------------
8
  client = Groq(api_key=os.getenv("GROQ_API_KEY"))
9
 
 
15
  # -----------------------------
16
  # Chat function
17
  # -----------------------------
18
+ def chat(user_message, history):
19
  if history is None:
20
  history = []
21
 
22
  if not history:
23
  history.append({"role": "system", "content": SYSTEM_PROMPT})
24
 
25
+ history.append({"role": "user", "content": user_message})
26
 
27
+ response = client.chat.completions.create(
28
  model="llama-3.3-70b-versatile",
29
  messages=history,
 
30
  temperature=1,
31
+ max_tokens=512,
32
  )
33
 
34
+ assistant_reply = response.choices[0].message.content
35
+ history.append({"role": "assistant", "content": assistant_reply})
36
 
37
  return history, history
38
 
 
44
  if not scenario.strip():
45
  return "Please enter a scenario."
46
 
47
+ response = client.chat.completions.create(
48
  model="llama-3.3-70b-versatile",
49
  messages=[
50
  {"role": "system", "content": "Generate a 6-scene storyboard in table format."},
 
53
  max_tokens=700,
54
  )
55
 
56
+ return response.choices[0].message.content
57
 
58
 
59
  # -----------------------------
60
+ # Gradio UI
61
  # -----------------------------
62
  with gr.Blocks(title="Storyboard Assistant") as demo:
63
  gr.Markdown("## ๐Ÿ“– Storyboard Assistant")
 
68
  state = gr.State([])
69
 
70
  user_input = gr.Textbox(label="Your Message")
71
+ send_btn = gr.Button("Ask")
72
 
73
+ send_btn.click(
74
+ chat,
75
  inputs=[user_input, state],
76
  outputs=[chatbot, state],
77
  )
78
 
79
  with gr.Tab("๐Ÿ“– Generate Storyboard"):
80
  scenario = gr.Textbox(label="Scenario")
81
+ generate_btn = gr.Button("Generate")
82
  output = gr.Textbox(lines=12)
83
 
84
+ generate_btn.click(
85
+ generate_storyboard,
86
+ inputs=scenario,
87
+ outputs=output,
88
+ )
89
 
90
 
91
  # -----------------------------
92
+ # Launch (CRITICAL FIX)
93
  # -----------------------------
94
+ if __name__ == "__main__":
95
+ demo.launch()