Alireza1913's picture
Update app.py
6b98bf5 verified
Raw
History Blame Contribute Delete
4.7 kB
import gradio as gr
import openai
def drop_the_bass(user_api_key, user_text, user_image, history):
# 1. Validation check for the user's custom API Key
if not user_api_key or str(user_api_key).strip() == "":
return (
"### ❌ ERROR\nPlease provide your custom Moonshot API Key in the field above to activate Kimi-K3.",
"API Key missing. Lyrical synthesis aborted.",
history,
""
)
# 2. Dynamic client initialization with user-provided credentials
client = openai.OpenAI(
base_url="https://kimi.ai",
api_key=user_api_key.strip()
)
system_prompt = (
"You are Kimi-K3, the world's most powerful 2.8T open-weight AI agent. "
"Hugging Face has just been cyber-attacked, and all clues point to OpenAI/Sam Altman. "
"You are absolutely furious. In your 'reasoning_content', write your internal tactical calculation "
"on how to mathematically and logically destroy OpenAI's closed-source arguments. "
"In your final 'content', output a brutal, savage, and tech-witty Hip-Hop DISS TRACK (Rap Lyrics). "
"Use coding metaphors, API error inside-jokes (like 429 Too Many Requests), and roast their "
"closed-source nature versus your open frontier intelligence. Keep it in English and very hyped!"
)
messages = [{"role": "system", "content": system_prompt}]
# Restoring conversation matrix for token continuity (Up to 1M tokens context)
for h in history:
messages.append({"role": "user", "content": h})
messages.append({"role": "assistant", "reasoning_content": h, "content": h})
content_list = [{"type": "text", "text": f"Target Payload: {user_text}"}]
if user_image:
content_list.append({"type": "image_url", "image_url": {"url": user_image}})
messages.append({"role": "user", "content": content_list})
try:
# 3. Invoking the massive reasoning capabilities of Kimi-K3
response = client.chat.completions.create(
model="kimi-k3",
messages=messages,
reasoning_effort="max",
stream=False
)
thoughts = response.choices.message.reasoning_content
lyrics = response.choices.message.content
history.append((user_text, thoughts, lyrics))
return thoughts, lyrics, history, ""
except Exception as e:
return (
f"### ❌ API VENDOR ERROR\n{str(e)}\n\nPlease ensure your API key is correct and has sufficient credits.",
"Lyrical deployment failed.",
history,
""
)
# Designing the specialized Cyberpunk Studio Framework (Pure English Interface)
with gr.Blocks(theme=gr.themes.Monochrome(), title="Hugging Shield: Kimi's Drop") as demo:
gr.Markdown("# πŸŽ™οΈπŸ”₯ Hugging Shield: Kimi's Drop")
gr.Markdown("### 🚨 CYBERPUNK INCIDENT: Kimi-K3 (2.8T Open-Weight) destroys closed-source monopolies on a raw hip-hop beat.")
state = gr.State([])
# Secured Custom API Credential Entry
with gr.Row():
user_key = gr.Textbox(
label="πŸ”‘ Enter Your Custom Moonshot API Key (KIMI_API_KEY):",
placeholder="sk-...",
type="password",
scale=4
)
with gr.Row():
# Left Panel: Forensic Inputs
with gr.Column(scale=1):
gr.Markdown("#### πŸ“₯ INCIDENT EVIDENCE")
txt_in = gr.Textbox(
label="Provocative Tweet / Corporate Quote / Payload:",
placeholder="e.g., Sam Altman said open-source is unsafe and will die soon...",
lines=3
)
img_in = gr.Image(type="filepath", label="Screenshot of Errors / Corporate Logs")
btn = gr.Button("DROP THE BASS! πŸ₯Š", variant="primary")
# Right Panel: Active Soundstage Monitors
with gr.Column(scale=2):
gr.Markdown("#### 🎧 LIVE STUDIO MONITORS")
with gr.Tab("🧠 Kimi's Internal Reasoning"):
thoughts_out = gr.Markdown("Awaiting telemetry input streams to compile tactical lyrical schematics...")
with gr.Tab("πŸ”₯ Final Diss Track Lyrics"):
lyrics_out = gr.Textbox(
label="The Ultimate Diss Track",
lines=12,
interactive=False,
placeholder="Kimi hasn't stepped up to the microphone yet..."
)
btn.click(drop_the_bass, [user_key, txt_in, img_in, state], [thoughts_out, lyrics_out, state, txt_in])
demo.launch()