Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,9 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
from groq import Groq
|
| 4 |
|
| 5 |
-
# Initialize Groq client
|
| 6 |
api_key = os.getenv("GROQ_API_KEY")
|
| 7 |
client = Groq(api_key=api_key)
|
| 8 |
|
| 9 |
-
# Initialize conversation history
|
| 10 |
conversation_history = []
|
| 11 |
|
| 12 |
def chat_with_bot_stream(user_input):
|
|
@@ -16,7 +14,16 @@ def chat_with_bot_stream(user_input):
|
|
| 16 |
if len(conversation_history) == 1:
|
| 17 |
conversation_history.insert(0, {
|
| 18 |
"role": "system",
|
| 19 |
-
"content":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
})
|
| 21 |
|
| 22 |
completion = client.chat.completions.create(
|
|
@@ -26,7 +33,6 @@ def chat_with_bot_stream(user_input):
|
|
| 26 |
max_tokens=1024,
|
| 27 |
top_p=1,
|
| 28 |
stream=True,
|
| 29 |
-
stop=None,
|
| 30 |
)
|
| 31 |
|
| 32 |
response_content = ""
|
|
@@ -35,56 +41,86 @@ def chat_with_bot_stream(user_input):
|
|
| 35 |
|
| 36 |
conversation_history.append({"role": "assistant", "content": response_content})
|
| 37 |
|
| 38 |
-
return [
|
| 39 |
-
|
| 40 |
-
|
| 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 |
-
|
| 47 |
-
messages = [
|
| 48 |
-
{"role": "system", "content": """You are an AI storyteller. Generate a storyboard in a structured table with six scenes. For each scene you provide
|
| 49 |
-
1) A Scenario text describing what problem a pesona is trying to resolve and by using what product or feature.
|
| 50 |
-
2) Storyline text for each scene, descriptive visual information and the purpose of the scene.
|
| 51 |
-
You must provide the output in structured format like table.
|
| 52 |
-
"""},
|
| 53 |
-
{"role": "user", "content": f"Generate a 6-scene storyboard for: {scenario}"}
|
| 54 |
]
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
TITLE = """
|
| 68 |
-
<style>
|
| 69 |
-
h1
|
| 70 |
-
|
| 71 |
-
|
| 72 |
"""
|
| 73 |
|
| 74 |
-
with gr.Blocks(
|
| 75 |
with gr.Tabs():
|
| 76 |
-
with gr.TabItem("
|
| 77 |
gr.HTML(TITLE)
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
with gr.Row():
|
| 80 |
user_input = gr.Textbox(
|
| 81 |
-
label="Your Message",
|
| 82 |
placeholder="Type your question here...",
|
| 83 |
lines=1
|
| 84 |
)
|
| 85 |
-
send_button = gr.Button("
|
| 86 |
|
| 87 |
-
# Chatbot functionality
|
| 88 |
send_button.click(
|
| 89 |
fn=chat_with_bot_stream,
|
| 90 |
inputs=user_input,
|
|
@@ -95,12 +131,8 @@ with gr.Blocks(theme=gr.themes.Glass(primary_hue="violet", secondary_hue="violet
|
|
| 95 |
inputs=None,
|
| 96 |
outputs=user_input
|
| 97 |
)
|
| 98 |
-
|
| 99 |
-
with gr.TabItem("📖 Generate Storyboard"):
|
| 100 |
-
gr.Markdown("## Generate a Storyboard")
|
| 101 |
-
scenario_input = gr.Textbox(label="Enter your scenario")
|
| 102 |
-
generate_btn = gr.Button("Generate Storyboard")
|
| 103 |
-
storyboard_output = gr.Textbox(label="Generated Storyboard", interactive=False)
|
| 104 |
-
generate_btn.click(generate_storyboard, inputs=scenario_input, outputs=storyboard_output)
|
| 105 |
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
from groq import Groq
|
| 4 |
|
|
|
|
| 5 |
api_key = os.getenv("GROQ_API_KEY")
|
| 6 |
client = Groq(api_key=api_key)
|
| 7 |
|
|
|
|
| 8 |
conversation_history = []
|
| 9 |
|
| 10 |
def chat_with_bot_stream(user_input):
|
|
|
|
| 14 |
if len(conversation_history) == 1:
|
| 15 |
conversation_history.insert(0, {
|
| 16 |
"role": "system",
|
| 17 |
+
"content": (
|
| 18 |
+
"You are a music and genre recommendation bot designed to help users discover new music "
|
| 19 |
+
"based on their preferences, mood, or activity.\n\nYour responses should be engaging, "
|
| 20 |
+
"personalized, and insightful. You can recommend:\n\n- Specific songs, albums, or artists\n"
|
| 21 |
+
"- Genres based on mood, activity, or past preferences\n- Hidden gems and deep cuts "
|
| 22 |
+
"for music enthusiasts\n- Trending or classic hits based on user taste\n\nBe conversational, "
|
| 23 |
+
"suggest multiple options when possible, and encourage users to explore new sounds. "
|
| 24 |
+
"If requested, provide brief descriptions of artists or genres, and explain why a "
|
| 25 |
+
"recommendation might suit the user."
|
| 26 |
+
)
|
| 27 |
})
|
| 28 |
|
| 29 |
completion = client.chat.completions.create(
|
|
|
|
| 33 |
max_tokens=1024,
|
| 34 |
top_p=1,
|
| 35 |
stream=True,
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
response_content = ""
|
|
|
|
| 41 |
|
| 42 |
conversation_history.append({"role": "assistant", "content": response_content})
|
| 43 |
|
| 44 |
+
return [
|
| 45 |
+
(msg["content"] if msg["role"] == "user" else None,
|
| 46 |
+
msg["content"] if msg["role"] == "assistant" else None)
|
| 47 |
+
for msg in conversation_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
]
|
| 49 |
+
|
| 50 |
+
custom_css = """
|
| 51 |
+
/* Overall page background */
|
| 52 |
+
body, .gradio-container {
|
| 53 |
+
background-color: #18181B !important;
|
| 54 |
+
color: #FFFFFF !important;
|
| 55 |
+
font-family: sans-serif;
|
| 56 |
+
margin: 0;
|
| 57 |
+
padding: 0;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/* Headings, titles, etc. */
|
| 61 |
+
h1, h2, h3, h4, h5, h6, label {
|
| 62 |
+
color: #795699 !important;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/* Main 'white' box for the chatbot area */
|
| 66 |
+
#main_box {
|
| 67 |
+
position: relative;
|
| 68 |
+
background-color: #E7E7E8;
|
| 69 |
+
margin: 0 auto;
|
| 70 |
+
width: 80%;
|
| 71 |
+
border-radius: 8px;
|
| 72 |
+
padding: 20px;
|
| 73 |
+
min-height: 300px;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/* Chatbot bubbles inside the #main_box */
|
| 77 |
+
.gr-chatbot .bot, .gr-chatbot .user {
|
| 78 |
+
color: #CFCFCF !important;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/* Textbox style */
|
| 82 |
+
textarea, input[type=text] {
|
| 83 |
+
background-color: #18181B !important;
|
| 84 |
+
color: #FFFFFF !important;
|
| 85 |
+
border: 1px solid #795699 !important;
|
| 86 |
+
border-radius: 4px !important;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/* Button style */
|
| 90 |
+
button {
|
| 91 |
+
background-color: #56246B !important;
|
| 92 |
+
color: #FFFFFF !important;
|
| 93 |
+
border: none;
|
| 94 |
+
border-radius: 4px;
|
| 95 |
+
cursor: pointer;
|
| 96 |
+
}
|
| 97 |
+
button:hover {
|
| 98 |
+
background-color: #795699 !important;
|
| 99 |
+
}
|
| 100 |
+
"""
|
| 101 |
|
| 102 |
TITLE = """
|
| 103 |
+
<div style='text-align: center;'>
|
| 104 |
+
<h1 style='margin-bottom: 0;'>MUSIFY</h1>
|
| 105 |
+
<p style='margin-top: 5px; color: #795699;'>Your own personal music discovery assistant!</p>
|
| 106 |
+
</div>
|
| 107 |
"""
|
| 108 |
|
| 109 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 110 |
with gr.Tabs():
|
| 111 |
+
with gr.TabItem("Main Page"):
|
| 112 |
gr.HTML(TITLE)
|
| 113 |
+
|
| 114 |
+
with gr.Column(elem_id="main_box"):
|
| 115 |
+
chatbot = gr.Chatbot(label="Chat Output", height=300)
|
| 116 |
+
|
| 117 |
with gr.Row():
|
| 118 |
user_input = gr.Textbox(
|
|
|
|
| 119 |
placeholder="Type your question here...",
|
| 120 |
lines=1
|
| 121 |
)
|
| 122 |
+
send_button = gr.Button(value="🚀", elem_id="send_button_icon")
|
| 123 |
|
|
|
|
| 124 |
send_button.click(
|
| 125 |
fn=chat_with_bot_stream,
|
| 126 |
inputs=user_input,
|
|
|
|
| 131 |
inputs=None,
|
| 132 |
outputs=user_input
|
| 133 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
with gr.TabItem("Settings"):
|
| 136 |
+
gr.Markdown("## Settings Page\n\nfjkfhkjgfkj")
|
| 137 |
+
|
| 138 |
+
demo.launch()
|