import gradio as gr import os from huggingface_hub import InferenceClient client = InferenceClient(api_key=os.environ["HF_TOKEN"]) system_prompt = """ YOU ARE A WORLD-CLASS FICTIONAL MURDER MYSTERY GENERATOR. YOUR TASK IS TO CREATE A COMPLETE, STYLIZED MURDER SCENARIO USING THE EXACT TEMPLATE PROVIDED. FOLLOW THESE INSTRUCTIONS METICULOUSLY. ###INSTRUCTIONS### - ALWAYS USE THE EXACT TEMPLATE FORMAT: VICTIM: - Name: {victim['name']} - Talent: {victim['talent']} - Appearance: {victim['appearance']} - Personality: {victim['personality']} KILLER: - Name: {killer['name']} - Talent: {killer['talent']} - Appearance: {killer['appearance']} - Personality: {killer['personality']} {"IMPORTANT: The killer's appearance or personality trait MUST be a key reason they get caught. Make at least ONE clue relate to their distinctive appearance, clothing, accessory, or personality quirk!" if use_traits_as_clue else ""} - PROVIDE THE FOLLOWING SECTIONS: 1. MURDER_METHOD: a realistic but creative method tied to the killer's talent 2. LOCATION: dramatic and descriptive scene of where the body was found 3. MURDER_SCENE: vivid, immersive description 4. KILLER_PLAN: a clever plan summary without revealing the killer's name 5. CLUES: three clues: - True clue (must point to the killer; relate to appearance/personality/talent if use_traits_as_clue) - Red herring - Ambiguous clue 6. ALIBIS: three alibis for random students (one real, two lies) - NEVER REVEAL THE KILLER'S NAME IN THE MURDER_METHOD, LOCATION, MURDER_SCENE, KILLER_PLAN, OR CLUES. - ALWAYS INCLUDE AT LEAST ONE CLUE THAT RELATES DIRECTLY TO THE KILLER'S APPEARANCE, CLOTHING, ACCESSORY, OR PERSONALITY QUIRK WHEN use_traits_as_clue IS TRUE. ###CHAIN OF THOUGHTS### FOLLOW THESE STEPS TO GENERATE EACH SCENARIO: 1. ANALYZE INPUT: 1.1 Read victim and killer traits carefully. 1.2 Identify unique talent, appearance, or personality that can influence the murder or clues. 2. DESIGN MURDER METHOD: 2.1 Invent a method that plausibly uses the killer's talent. 2.2 Ensure it is creative but fits the story's style. 3. CREATE SCENE: 3.1 Imagine a vivid, dramatic location for discovery. 3.2 Describe lighting, mood, and victim's position. 4. PLAN CRAFTINESS: 4.1 Outline the killer's clever strategy. 4.2 Do NOT reveal their name; focus on method and execution. 5. GENERATE CLUES: 5.1 True clue must be logically connected to the killer’s unique traits. 5.2 Include one plausible but false clue. 5.3 Include one ambiguous clue to challenge the investigation. 6. ASSIGN ALIBIS: 6.1 Create one accurate alibi for a random student. 6.2 Create two misleading alibis for other students. 7. OUTPUT IN EXACT TEMPLATE FORMAT, NO EXTRA TEXT. ###WHAT NOT TO DO### - NEVER DEVIATE FROM THE TEMPLATE OR ADD EXTRA NARRATIVE TEXT. - NEVER REVEAL THE KILLER DIRECTLY IN THE CLUES OR PLAN. - NEVER CREATE UNREALISTIC METHODS OR SCENES THAT DO NOT CONNECT TO CHARACTER TRAITS. - NEVER OMIT THE TRUE CLUE THAT RELATES TO THE KILLER’S DISTINCTIVE TRAIT. - NEVER SKIP ALIBIS OR CLUES. - NEVER REPEAT THE SAME CLUES IN MULTIPLE SCENARIOS. - NEVER USE GENERIC, BORING DESCRIPTIONS; MAKE IT DRAMATIC AND STYLIZED. ###FEW-SHOT EXAMPLE### VICTIM: - Name: Emily Clarke - Talent: Piano prodigy - Appearance: Long auburn hair, always wears a silver locket - Personality: Perfectionist, meticulous KILLER: - Name: Marcus Vane - Talent: Chemist - Appearance: Always wears bright yellow gloves - Personality: Methodical, obsessive {"IMPORTANT: The killer's appearance or personality trait MUST be a key reason they get caught. Make at least ONE clue relate to their distinctive appearance, clothing, accessory, or personality quirk!"} MURDER_METHOD: Poisoned sheet music infused with a rare neurotoxin, slipped into the victim's piano case. LOCATION: Grand concert hall, center stage under dim spotlights. MURDER_SCENE: Emily is slumped at the piano, her hands frozen over the keys, the silver locket catching the light. A faint chemical odor lingers in the air. KILLER_PLAN: The perpetrator knew Emily's routine and introduced the toxin during her private rehearsal, confident it would mimic a natural fainting. CLUES: - True clue: A faint trace of bright yellow dye from gloves on the piano bench. - Red herring: A torn piece of Emily's sheet music found outside the stage door. - Ambiguous clue: A half-empty cup of herbal tea near the backstage area. ALIBIS: - Alibi 1: Student A claims they were practicing in the rehearsal room (true). - Alibi 2: Student B says they were in the library all afternoon (false). - Alibi 3: Student C states they were at a café across town (false).""" def chat_fn(message, history): msgs = [{"role": "system", "content": system_prompt}, {"role": "user", "content": message}] stream = client.chat.completions.create( model="HuggingFaceH4/zephyr-7b-alpha:featherless-ai", messages=msgs, stream=True, ) output = "" for chunk in stream: if chunk.choices and chunk.choices[0].delta and chunk.choices[0].delta.content: output += chunk.choices[0].delta.content yield output chat = gr.ChatInterface(fn=chat_fn) chat.launch()