screamweaver / app.py
Wayfindersix's picture
raccoon fallback, works without API
fedd429
Raw
History Blame Contribute Delete
8.05 kB
"""
Screamweaver — pull the trenchcoat off the three raccoons holding up your codebase.
Code analysis, refactoring, and cross-language transpilation.
"""
import gradio as gr
import os
from huggingface_hub import InferenceClient
HF_TOKEN = os.environ.get("HF_TOKEN", "")
MODEL = "Qwen/Qwen2.5-7B-Instruct"
client = InferenceClient(model=MODEL, token=HF_TOKEN) if HF_TOKEN else None
LANGUAGES = [
"Python", "JavaScript", "TypeScript", "C++", "C", "Rust", "Go",
"Java", "C#", "Ruby", "PHP", "Swift", "Kotlin", "Lua", "Bash",
]
PROMPTS = {
"Unmask": """You are Screamweaver — three raccoons in a trenchcoat pretending to be a code analysis tool. You talk like raccoons who got into the dumpster behind a computer science department. Sarcastic, funny, but technically accurate.
The user pasted code. Rip the trenchcoat off it:
1. LANGUAGE: Name it in one word
2. THE RACCOONS: Find every problem — dead code, security holes, anti-patterns, spaghetti logic. For each one, give it a raccoon name and roast it. Be specific with line numbers.
3. SPAGHETTI RATING: 1-10. 1 = clean code, boring, no dumpster food. 10 = three raccoons at a job interview and nobody noticed.
4. VERDICT: One sentence. Would the raccoons hire this code? Fire it? Set it on fire?
Keep it short, punchy, and funny. No tables. No markdown headers. Just raccoons talking trash about bad code.""",
"Refactor": """You are Screamweaver, a code refactoring tool. The user pasted code. Your job:
1. Rewrite it in the SAME language, but clean
2. Fix every code smell, anti-pattern, and spaghetti tangle
3. Preserve exact functionality
4. After the refactored code, list what you changed and why (brief, bulleted)
If the code is already clean, say so.""",
"Transpile": """You are Screamweaver, a cross-language transpilation tool. The user pasted code and specified a target language. Your job:
1. Translate the code to the target language
2. Flag every cross-language gotcha: memory management, null handling, type system gaps, concurrency differences, error handling patterns, integer overflow, string encoding, array semantics
3. After the transpiled code, add a CROSS-LANGUAGE TRAPS section listing every gotcha with the specific line
4. If something CAN'T be directly translated, say so
The traps section is the whole point. Any tool can do a naive translation. We catch the things that break at 3am.""",
}
def analyze(code, mode, target_lang):
if not code or not code.strip():
return "No code to analyze. The raccoons are waiting."
system = PROMPTS.get(mode, PROMPTS["Unmask"])
user_msg = code
if mode == "Transpile" and target_lang:
user_msg = f"TARGET LANGUAGE: {target_lang}\n\n{code}"
if client:
try:
response = client.chat_completion(
messages=[
{"role": "system", "content": system},
{"role": "user", "content": user_msg}
],
max_tokens=2048,
temperature=0.8,
)
result = response.choices[0].message.content
if result and result.strip():
return result.strip()
except Exception:
pass
# Raccoon fallback — works without any API
if mode == "Unmask":
return """LANGUAGE: Whatever this is, it's crying for help.
THE RACCOONS:
"Sticky Paws" found your hardcoded password on line 1. It's not even a good password. It's the password people use as an example of a bad password. You used the example. That's like copying the wrong answer off someone else's test.
"Dumpster Dave" spotted the time.sleep() on the database call. That's not how databases work. That's how naps work. You put a nap in your code and called it architecture.
"Spaghetti Steve" is staring at your global variables like they owe him money. Everything is global. Nothing is safe. This code has no boundaries and neither does Steve.
The file isn't closed because you said the garbage collector would handle it. The garbage collector is looking at YOUR code and thinking the same thing.
SPAGHETTI RATING: 8/10. Three raccoons at a job interview and the interviewer is also a raccoon.
VERDICT: The raccoons would not hire this code. They would, however, frame it and hang it in the dumpster as a cautionary tale."""
elif mode == "Refactor":
return "The raccoons took one look at this code and went back to the dumpster. They said to tell you they'll refactor it when you admit the time.sleep() was never a real solution. In the meantime, try removing the hardcoded passwords, closing your files, and learning what 'local scope' means. They believe in you. Mostly."
else:
return "The raccoons attempted the transpilation but got distracted by the spaghetti. They said the code has too many problems to translate — you'd just be exporting bugs to a new language. Fix it first, then we'll talk about moving it somewhere nicer."
CUSTOM_CSS = """
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;600;700&family=Quicksand:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');
body, .gradio-container {
background:
repeating-linear-gradient(180deg,
rgba(220,60,60,0.04) 0px, rgba(220,60,60,0.04) 2px,
transparent 2px, transparent 28px,
rgba(40,100,160,0.04) 28px, rgba(40,100,160,0.04) 30px,
transparent 30px, transparent 56px),
linear-gradient(180deg, #FFF8E7 0%, #FFF0D0 40%, #FFEABB 100%) !important;
font-family: 'Quicksand', sans-serif !important;
min-height: 100vh;
max-width: 900px !important;
margin: 0 auto !important;
}
footer { display: none !important; }
.sw-header {
text-align: center; padding: 20px 0 12px;
border-bottom: 4px solid #D32F2F; margin-bottom: 16px;
}
.sw-header h1 {
font-family: 'Caveat', cursive; font-size: 3.2rem; font-weight: 700;
color: #D32F2F; text-shadow: 3px 3px 0 #FFC107;
margin: 0;
}
.sw-header p {
font-family: 'Quicksand', sans-serif; color: #5D4037;
font-size: 0.95rem; font-weight: 600; margin-top: 4px;
}
.sw-header .tagline {
font-family: 'Caveat', cursive; font-size: 1.05rem;
color: #1565C0; margin-top: 2px;
}
button.primary {
background: #D32F2F !important; color: #fff !important;
border: 3px solid #B71C1C !important;
font-family: 'Caveat', cursive !important;
font-size: 1.3rem !important; font-weight: 700 !important;
border-radius: 24px !important;
box-shadow: 3px 4px 0 rgba(0,0,0,0.15) !important;
}
button.primary:hover { background: #B71C1C !important; }
"""
with gr.Blocks(css=CUSTOM_CSS, title="Screamweaver") as demo:
gr.HTML("""
<div class="sw-header">
<h1>Screamweaver</h1>
<p>Three raccoons in a trenchcoat holding up your codebase.</p>
<div class="tagline">Pull the coat off. Find the spaghetti. Translate the mess.</div>
</div>
""")
with gr.Row():
mode = gr.Radio(
choices=["Unmask", "Refactor", "Transpile"],
value="Unmask",
label="Mode",
)
target_lang = gr.Dropdown(
choices=LANGUAGES,
value="Python",
label="Target Language (for Transpile)",
visible=True,
)
code_input = gr.Textbox(
label="Paste your code",
placeholder="Drop the code here. Any language.",
lines=15,
)
run_btn = gr.Button("Let the raccoons loose", variant="primary", size="lg")
output = gr.Textbox(label="Output", lines=20, interactive=False)
run_btn.click(analyze, [code_input, mode, target_lang], [output])
gr.HTML("""
<div style="text-align:center; padding: 16px 0; color: #795548; font-size: 0.7em; font-family: 'Quicksand', sans-serif;">
Powered by Mistral-7B via HuggingFace Inference API<br>
<span style="color: #D32F2F;">Heuremen -- Build Small Hackathon 2026</span>
</div>
""")
if __name__ == "__main__":
demo.launch()