Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,13 +1,87 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
with
|
| 7 |
-
|
| 8 |
-
name = gr.Textbox(label="Name")
|
| 9 |
-
out = gr.Textbox(label="Output")
|
| 10 |
-
btn = gr.Button("Greet")
|
| 11 |
-
btn.click(greet, inputs=name, outputs=out)
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
|
| 4 |
+
def get_client():
|
| 5 |
+
key = os.environ.get("DEEPSEEK_API_KEY", "")
|
| 6 |
+
if not key:
|
| 7 |
+
return None
|
| 8 |
+
from openai import OpenAI
|
| 9 |
+
return OpenAI(api_key=key, base_url="https://api.deepseek.com")
|
| 10 |
|
| 11 |
+
with open("SOUL.md") as f:
|
| 12 |
+
SOUL_TEMPLATE = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
def compare(prompt, model="deepseek-v4-pro"):
|
| 15 |
+
if not prompt.strip():
|
| 16 |
+
return "Enter a prompt to compare.", "", ""
|
| 17 |
+
|
| 18 |
+
client = get_client()
|
| 19 |
+
if not client:
|
| 20 |
+
return "Add DEEPSEEK_API_KEY in Space Settings → Repository secrets.", "", ""
|
| 21 |
+
|
| 22 |
+
raw = client.chat.completions.create(
|
| 23 |
+
model=model,
|
| 24 |
+
messages=[{"role": "user", "content": prompt}],
|
| 25 |
+
temperature=0.7,
|
| 26 |
+
)
|
| 27 |
+
raw_text = raw.choices[0].message.content
|
| 28 |
+
raw_cost = f"Tokens: {raw.usage.total_tokens} | ~${raw.usage.total_tokens * 3 / 1_000_000:.4f}"
|
| 29 |
+
|
| 30 |
+
with_soul = client.chat.completions.create(
|
| 31 |
+
model=model,
|
| 32 |
+
messages=[
|
| 33 |
+
{"role": "system", "content": SOUL_TEMPLATE},
|
| 34 |
+
{"role": "user", "content": prompt}
|
| 35 |
+
],
|
| 36 |
+
temperature=0.7,
|
| 37 |
+
)
|
| 38 |
+
soul_text = with_soul.choices[0].message.content
|
| 39 |
+
soul_cost = f"Tokens: {with_soul.usage.total_tokens} | ~${with_soul.usage.total_tokens * 3 / 1_000_000:.4f}"
|
| 40 |
+
|
| 41 |
+
return raw_text, soul_text, f"Raw: {raw_cost} | With SOUL: {soul_cost}"
|
| 42 |
+
|
| 43 |
+
with gr.Blocks(title="Poor Mans Opus Before After", theme=gr.themes.Soft()) as demo:
|
| 44 |
+
gr.Markdown("""
|
| 45 |
+
# Poor Mans Opus — Live Comparison
|
| 46 |
+
|
| 47 |
+
Same model. Same price. Different soul.
|
| 48 |
+
Left: DeepSeek V4 Pro. Right: Same model + `::GENE{}` behavioral DNA.
|
| 49 |
+
""")
|
| 50 |
+
|
| 51 |
+
if not os.environ.get("DEEPSEEK_API_KEY"):
|
| 52 |
+
gr.Markdown("""
|
| 53 |
+
⚠️ **API key not configured.**
|
| 54 |
+
Add `DEEPSEEK_API_KEY` in [Space Settings](https://huggingface.co/spaces/ilanguage/poor-mans-opus-demo/settings) → Repository secrets.
|
| 55 |
+
""")
|
| 56 |
+
|
| 57 |
+
model_choice = gr.Dropdown(
|
| 58 |
+
choices=["deepseek-v4-pro", "deepseek-v4-flash"],
|
| 59 |
+
value="deepseek-v4-pro", label="Model"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
prompt = gr.Textbox(
|
| 63 |
+
label="Your prompt",
|
| 64 |
+
placeholder="e.g. Explain quantum computing to a 10-year-old",
|
| 65 |
+
lines=3
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
btn = gr.Button("Compare", variant="primary")
|
| 69 |
+
|
| 70 |
+
with gr.Row():
|
| 71 |
+
with gr.Column():
|
| 72 |
+
gr.Markdown("### Raw DeepSeek")
|
| 73 |
+
raw_out = gr.Textbox(label="", lines=16)
|
| 74 |
+
with gr.Column():
|
| 75 |
+
gr.Markdown("### With Poor Mans Opus")
|
| 76 |
+
soul_out = gr.Textbox(label="", lines=16)
|
| 77 |
+
|
| 78 |
+
stats = gr.Textbox(label="Cost comparison", interactive=False)
|
| 79 |
+
|
| 80 |
+
btn.click(compare, inputs=[prompt, model_choice], outputs=[raw_out, soul_out, stats])
|
| 81 |
+
|
| 82 |
+
gr.Markdown("""
|
| 83 |
+
[GitHub](https://github.com/mtmpss/poor-mans-opus) | [ClawHub](https://clawhub.ai/mtmpss/poor-mans-opus) | [HF Model](https://huggingface.co/ilanguage/poor-mans-opus)
|
| 84 |
+
""")
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
demo.launch()
|