Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines345667895 unmodified lines1516171818192021222324252526272728293030313233343534353637385 unmodified lines44454647474849502 unmodified lines535455565657585960606162634 unmodified lines68697071717273747374757677787980818182838484858687888990918892939091929394952 unmodified linesfrom groq import Groq
# -----------------------------# Initialize Groq# Groq Client# -----------------------------client = Groq(api_key=os.getenv("GROQ_API_KEY"))
5 unmodified lines# -----------------------------# Chat function# -----------------------------def chat_with_bot(user_input, history):def chat(user_message, history): if history is None: history = []
if not history: history.append({"role": "system", "content": SYSTEM_PROMPT})
history.append({"role": "user", "content": user_input}) history.append({"role": "user", "content": user_message})
completion = client.chat.completions.create( response = client.chat.completions.create( model="llama-3.3-70b-versatile", messages=history, max_tokens=512, temperature=1, max_tokens=512, )
reply = completion.choices[0].message.content history.append({"role": "assistant", "content": reply}) assistant_reply = response.choices[0].message.content history.append({"role": "assistant", "content": assistant_reply})
return history, history
5 unmodified lines if not scenario.strip(): return "Please enter a scenario."
completion = client.chat.completions.create( response = client.chat.completions.create( model="llama-3.3-70b-versatile", messages=[ {"role": "system", "content": "Generate a 6-scene storyboard in table format."},2 unmodified lines max_tokens=700, )
return completion.choices[0].message.content return response.choices[0].message.content
# -----------------------------# UI# Gradio UI# -----------------------------with gr.Blocks(title="Storyboard Assistant") as demo: gr.Markdown("## 📖 Storyboard Assistant")4 unmodified lines state = gr.State([])
user_input = gr.Textbox(label="Your Message") send = gr.Button("Ask") send_btn = gr.Button("Ask")
send.click( chat_with_bot, send_btn.click( chat, inputs=[user_input, state], outputs=[chatbot, state], )
with gr.Tab("📖 Generate Storyboard"): scenario = gr.Textbox(label="Scenario") generate = gr.Button("Generate") generate_btn = gr.Button("Generate") output = gr.Textbox(lines=12)
generate.click(generate_storyboard, scenario, output) generate_btn.click( generate_storyboard, inputs=scenario, outputs=output, )
# -----------------------------# 🚨 CRITICAL LAUNCH FIX# Launch (CRITICAL FIX)# -----------------------------demo.launch( ssr=False, # ✅ disables schema bug show_api=False # ✅ prevents /api/info crash)if __name__ == "__main__": demo.launch()app.py+22-20