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