basantyahya commited on
Commit
84e3a3d
·
verified ·
1 Parent(s): 33b41cb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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,
23
+ messages=messages,
24
+ temperature=temperature,
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="🎬 Storyboard Generator AI",
35
+ description="Create professional storyboards for films, animations, and more!",
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()