Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,87 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
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 |
-
|
| 10 |
-
SYSTEM_PROMPT = (
|
| 11 |
-
"You are an expert in storyboarding. "
|
| 12 |
-
"Provide clear, structured, and creative responses."
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
# -----------------------------
|
| 16 |
-
# Chat logic (Interface-safe)
|
| 17 |
-
# -----------------------------
|
| 18 |
-
def chat(user_input, history):
|
| 19 |
-
if history is None:
|
| 20 |
-
history = []
|
| 21 |
-
|
| 22 |
-
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 23 |
-
for u, a in history:
|
| 24 |
-
messages.append({"role": "user", "content": u})
|
| 25 |
-
messages.append({"role": "assistant", "content": a})
|
| 26 |
-
|
| 27 |
-
messages.append({"role": "user", "content": user_input})
|
| 28 |
-
|
| 29 |
-
completion = client.chat.completions.create(
|
| 30 |
-
model="llama-3.3-70b-versatile",
|
| 31 |
-
messages=messages,
|
| 32 |
-
max_tokens=512,
|
| 33 |
-
temperature=1,
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
reply = completion.choices[0].message.content
|
| 37 |
-
history.append((user_input, reply))
|
| 38 |
-
|
| 39 |
-
return history
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
# -----------------------------
|
| 43 |
-
# Storyboard generator
|
| 44 |
-
# -----------------------------
|
| 45 |
-
def generate_storyboard(scenario):
|
| 46 |
-
if not scenario.strip():
|
| 47 |
-
return "Please enter a scenario."
|
| 48 |
-
|
| 49 |
-
completion = client.chat.completions.create(
|
| 50 |
-
model="llama-3.3-70b-versatile",
|
| 51 |
-
messages=[
|
| 52 |
-
{"role": "system", "content": "Generate a 6-scene storyboard in table format."},
|
| 53 |
-
{"role": "user", "content": scenario},
|
| 54 |
-
],
|
| 55 |
-
max_tokens=700,
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
return completion.choices[0].message.content
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
# -----------------------------
|
| 62 |
-
# UI (Interface ONLY)
|
| 63 |
-
# -----------------------------
|
| 64 |
-
chat_ui = gr.Interface(
|
| 65 |
-
fn=chat,
|
| 66 |
-
inputs=gr.Textbox(label="Your Message"),
|
| 67 |
-
outputs=gr.Chatbot(label="Storyboard Chat"),
|
| 68 |
-
title="📖 Storyboard Assistant",
|
| 69 |
-
)
|
| 70 |
-
|
| 71 |
-
storyboard_ui = gr.Interface(
|
| 72 |
-
fn=generate_storyboard,
|
| 73 |
-
inputs=gr.Textbox(label="Scenario"),
|
| 74 |
-
outputs=gr.Textbox(lines=12),
|
| 75 |
-
title="📖 Storyboard Generator",
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
# -----------------------------
|
| 79 |
-
# App
|
| 80 |
-
# -----------------------------
|
| 81 |
-
demo = gr.TabbedInterface(
|
| 82 |
-
[chat_ui, storyboard_ui],
|
| 83 |
-
["💬 Chat", "📖 Storyboard"]
|
| 84 |
-
)
|
| 85 |
-
|
| 86 |
-
if __name__ == "__main__":
|
| 87 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|