Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ client = Groq(api_key=api_key)
|
|
9 |
# Initialize conversation history
|
10 |
conversation_history = []
|
11 |
|
12 |
-
def chat_with_bot_stream(user_input
|
13 |
global conversation_history
|
14 |
conversation_history.append({"role": "user", "content": user_input})
|
15 |
|
@@ -22,9 +22,9 @@ def chat_with_bot_stream(user_input, temperature, top_p):
|
|
22 |
completion = client.chat.completions.create(
|
23 |
model="llama3-70b-8192",
|
24 |
messages=conversation_history,
|
25 |
-
temperature=
|
26 |
-
top_p=top_p,
|
27 |
max_tokens=1024,
|
|
|
28 |
stream=True,
|
29 |
stop=None,
|
30 |
)
|
@@ -35,10 +35,12 @@ def chat_with_bot_stream(user_input, temperature, top_p):
|
|
35 |
|
36 |
conversation_history.append({"role": "assistant", "content": response_content})
|
37 |
|
38 |
-
return
|
|
|
|
|
39 |
|
40 |
# Function to generate a storyboard
|
41 |
-
def generate_storyboard(scenario
|
42 |
if not scenario.strip():
|
43 |
return "Please provide a scenario to generate the storyboard."
|
44 |
|
@@ -50,9 +52,9 @@ def generate_storyboard(scenario, temperature, top_p):
|
|
50 |
completion = client.chat.completions.create(
|
51 |
model="llama3-70b-8192",
|
52 |
messages=messages,
|
53 |
-
temperature=
|
54 |
-
top_p=top_p,
|
55 |
max_tokens=1024,
|
|
|
56 |
stream=False,
|
57 |
stop=None,
|
58 |
)
|
@@ -65,45 +67,11 @@ h1 { text-align: center; font-size: 24px; margin-bottom: 10px; }
|
|
65 |
<h1>📖 Storyboard Assistant</h1>
|
66 |
"""
|
67 |
|
68 |
-
example_scenarios = [
|
69 |
-
"A futuristic cityscape under AI governance.",
|
70 |
-
"A detective solving a mystery in a cyberpunk world.",
|
71 |
-
"A young explorer discovering an ancient civilization.",
|
72 |
-
"A spaceship crew encountering an unknown planet.",
|
73 |
-
"A medieval knight navigating political intrigue."
|
74 |
-
]
|
75 |
-
|
76 |
-
example_questions = [
|
77 |
-
"How do I create a compelling storyboard?",
|
78 |
-
"What are the key elements of a good visual story?",
|
79 |
-
"How can AI help with storyboarding?",
|
80 |
-
"What are common mistakes in storyboarding?",
|
81 |
-
"How do I structure a scene effectively?"
|
82 |
-
]
|
83 |
-
|
84 |
-
temperature_component = gr.Slider(
|
85 |
-
minimum=0,
|
86 |
-
maximum=1,
|
87 |
-
value=1,
|
88 |
-
step=0.01,
|
89 |
-
label="Temperature",
|
90 |
-
info="Controls randomness. Lower values make responses more deterministic."
|
91 |
-
)
|
92 |
-
|
93 |
-
top_p_component = gr.Slider(
|
94 |
-
minimum=0,
|
95 |
-
maximum=1,
|
96 |
-
value=1,
|
97 |
-
step=0.01,
|
98 |
-
label="Top-P Sampling",
|
99 |
-
info="Limits token selection to tokens with a cumulative probability up to P."
|
100 |
-
)
|
101 |
-
|
102 |
with gr.Blocks(theme=gr.themes.Glass(primary_hue="violet", secondary_hue="emerald", neutral_hue="stone")) as demo:
|
103 |
with gr.Tabs():
|
104 |
with gr.TabItem("💬Chat"):
|
105 |
gr.HTML(TITLE)
|
106 |
-
chatbot = gr.Chatbot(label="Storyboard Chatbot"
|
107 |
with gr.Row():
|
108 |
user_input = gr.Textbox(
|
109 |
label="Your Message",
|
@@ -112,25 +80,10 @@ with gr.Blocks(theme=gr.themes.Glass(primary_hue="violet", secondary_hue="emeral
|
|
112 |
)
|
113 |
send_button = gr.Button("✋Ask Question")
|
114 |
|
115 |
-
with gr.Accordion("🛠️ Customize Chatbot", open=False):
|
116 |
-
gr.Row([temperature_component, top_p_component])
|
117 |
-
|
118 |
-
with gr.Accordion("🧪 Example Questions", open=False):
|
119 |
-
example_radio = gr.Radio(
|
120 |
-
choices=example_questions,
|
121 |
-
label="Example Queries",
|
122 |
-
info="Select an example question or enter your own."
|
123 |
-
)
|
124 |
-
example_radio.change(
|
125 |
-
fn=lambda q: q if q else "No question selected.",
|
126 |
-
inputs=[example_radio],
|
127 |
-
outputs=[user_input]
|
128 |
-
)
|
129 |
-
|
130 |
# Chatbot functionality
|
131 |
send_button.click(
|
132 |
fn=chat_with_bot_stream,
|
133 |
-
inputs=
|
134 |
outputs=chatbot,
|
135 |
queue=True
|
136 |
).then(
|
@@ -142,27 +95,8 @@ with gr.Blocks(theme=gr.themes.Glass(primary_hue="violet", secondary_hue="emeral
|
|
142 |
with gr.TabItem("📖 Generate Storyboard"):
|
143 |
gr.Markdown("## Generate a Storyboard")
|
144 |
scenario_input = gr.Textbox(label="Enter your scenario")
|
145 |
-
example_radio = gr.Radio(
|
146 |
-
choices=example_scenarios,
|
147 |
-
label="Example Scenarios",
|
148 |
-
info="Select an example scenario or enter your own."
|
149 |
-
)
|
150 |
generate_btn = gr.Button("Generate Storyboard")
|
151 |
storyboard_output = gr.Textbox(label="Generated Storyboard", interactive=False)
|
152 |
-
|
153 |
-
with gr.Accordion("🛠️ Customize Storyboard", open=False):
|
154 |
-
gr.Row([temperature_component, top_p_component])
|
155 |
-
|
156 |
-
generate_btn.click(
|
157 |
-
generate_storyboard,
|
158 |
-
inputs=[scenario_input, temperature_component, top_p_component],
|
159 |
-
outputs=storyboard_output
|
160 |
-
)
|
161 |
-
|
162 |
-
example_radio.change(
|
163 |
-
fn=lambda scenario: scenario if scenario else "No scenario selected.",
|
164 |
-
inputs=[example_radio],
|
165 |
-
outputs=[scenario_input]
|
166 |
-
)
|
167 |
|
168 |
demo.launch()
|
|
|
9 |
# Initialize conversation history
|
10 |
conversation_history = []
|
11 |
|
12 |
+
def chat_with_bot_stream(user_input):
|
13 |
global conversation_history
|
14 |
conversation_history.append({"role": "user", "content": user_input})
|
15 |
|
|
|
22 |
completion = client.chat.completions.create(
|
23 |
model="llama3-70b-8192",
|
24 |
messages=conversation_history,
|
25 |
+
temperature=1,
|
|
|
26 |
max_tokens=1024,
|
27 |
+
top_p=1,
|
28 |
stream=True,
|
29 |
stop=None,
|
30 |
)
|
|
|
35 |
|
36 |
conversation_history.append({"role": "assistant", "content": response_content})
|
37 |
|
38 |
+
return [(msg["content"] if msg["role"] == "user" else None,
|
39 |
+
msg["content"] if msg["role"] == "assistant" else None)
|
40 |
+
for msg in conversation_history]
|
41 |
|
42 |
# Function to generate a storyboard
|
43 |
+
def generate_storyboard(scenario):
|
44 |
if not scenario.strip():
|
45 |
return "Please provide a scenario to generate the storyboard."
|
46 |
|
|
|
52 |
completion = client.chat.completions.create(
|
53 |
model="llama3-70b-8192",
|
54 |
messages=messages,
|
55 |
+
temperature=1,
|
|
|
56 |
max_tokens=1024,
|
57 |
+
top_p=1,
|
58 |
stream=False,
|
59 |
stop=None,
|
60 |
)
|
|
|
67 |
<h1>📖 Storyboard Assistant</h1>
|
68 |
"""
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
with gr.Blocks(theme=gr.themes.Glass(primary_hue="violet", secondary_hue="emerald", neutral_hue="stone")) as demo:
|
71 |
with gr.Tabs():
|
72 |
with gr.TabItem("💬Chat"):
|
73 |
gr.HTML(TITLE)
|
74 |
+
chatbot = gr.Chatbot(label="Storyboard Chatbot")
|
75 |
with gr.Row():
|
76 |
user_input = gr.Textbox(
|
77 |
label="Your Message",
|
|
|
80 |
)
|
81 |
send_button = gr.Button("✋Ask Question")
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
# Chatbot functionality
|
84 |
send_button.click(
|
85 |
fn=chat_with_bot_stream,
|
86 |
+
inputs=user_input,
|
87 |
outputs=chatbot,
|
88 |
queue=True
|
89 |
).then(
|
|
|
95 |
with gr.TabItem("📖 Generate Storyboard"):
|
96 |
gr.Markdown("## Generate a Storyboard")
|
97 |
scenario_input = gr.Textbox(label="Enter your scenario")
|
|
|
|
|
|
|
|
|
|
|
98 |
generate_btn = gr.Button("Generate Storyboard")
|
99 |
storyboard_output = gr.Textbox(label="Generated Storyboard", interactive=False)
|
100 |
+
generate_btn.click(generate_storyboard, inputs=scenario_input, outputs=storyboard_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
demo.launch()
|