| import gradio as gr |
| import openai |
|
|
| def drop_the_bass(user_api_key, user_text, user_image, history): |
| |
| 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, |
| "" |
| ) |
| |
| |
| 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}] |
| |
| |
| 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: |
| |
| 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, |
| "" |
| ) |
|
|
| |
| 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([]) |
| |
| |
| 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(): |
| |
| 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") |
| |
| |
| 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() |
|
|