File size: 4,696 Bytes
07015cb 6b98bf5 aa07439 6b98bf5 aa07439 74d1623 6b98bf5 74d1623 6b98bf5 74d1623 07015cb 6b98bf5 07015cb 6b98bf5 07015cb aa07439 07015cb 6b98bf5 07015cb 74d1623 07015cb 6b98bf5 07015cb 6b98bf5 07015cb 6b98bf5 07015cb 74d1623 07015cb 6b98bf5 07015cb 6b98bf5 07015cb aa07439 6b98bf5 aa07439 6b98bf5 aa07439 07015cb 6b98bf5 07015cb aa07439 6b98bf5 aa07439 6b98bf5 07015cb 6b98bf5 07015cb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | 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()
|