CoolFace
Apppublic

tunedailabs/philosopher

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
app.py85 linesDownload Raw Back to root
1import gradio as gr2from openai import OpenAI3 4# Modal endpoint — keep deployed: modal deploy philosopher_modal.py5MODAL_URL = "https://mark-gentry--qwen3-philosopher-serve.modal.run/v1"6MODEL_ID  = "qwen3-philosopher"7 8client = OpenAI(base_url=MODAL_URL, api_key="unused")9 10SYSTEM_PROMPT = (11    "You are a philosopher trained to reason carefully and rigorously. "12    "When given a question or position, construct a structured argument — "13    "identify the key claims, examine the assumptions, consider serious objections, "14    "and defend or revise your position in light of them. "15    "Do not merely summarise what philosophers have said. Reason."16)17 18def chat(message, history):19    messages = [{"role": "system", "content": SYSTEM_PROMPT}]20    for human, assistant in history:21        messages.append({"role": "user",      "content": human})22        messages.append({"role": "assistant", "content": assistant})23    messages.append({"role": "user", "content": message})24 25    response = ""26    try:27        stream = client.chat.completions.create(28            model=MODEL_ID,29            messages=messages,30            max_tokens=1500,31            temperature=0.7,32            stream=True,33        )34        for chunk in stream:35            delta = chunk.choices[0].delta.content or ""36            response += delta37            yield response38    except Exception as e:39        yield f"Model unavailable — the philosopher is thinking elsewhere. ({e})"40 41 42with gr.Blocks(43    theme=gr.themes.Base(44        primary_hue="indigo",45        font=[gr.themes.GoogleFont("Georgia"), "serif"],46    ),47    title="The Philosopher — TunedAI Labs",48    css="""49        .gradio-container { max-width: 800px; margin: auto; }50        .chat-message { font-size: 15px; line-height: 1.7; }51        footer { display: none; }52    """53) as demo:54 55    gr.Markdown("""56# The Philosopher57 58A 27B model fine-tuned to reason philosophically — not retrieve positions.59Ask it anything in philosophy of mind, ethics, metaphysics, or epistemology.60It will construct an argument, not a summary.61 62*Built on Qwen3.6-27B · DPO fine-tuned · [TunedAI Labs](https://tunedailabs.com)*63    """)64 65    chatbot = gr.ChatInterface(66        fn=chat,67        chatbot=gr.Chatbot(height=500, elem_classes=["chat-message"]),68        textbox=gr.Textbox(69            placeholder="Ask a philosophical question or state a position to argue against...",70            container=False,71        ),72        examples=[73            "Is consciousness reducible to physical processes?",74            "Does personal identity persist through radical change?",75            "Can free will exist in a deterministic universe?",76            "What is the strongest argument against moral realism?",77            "Argue against Chalmers' hard problem of consciousness.",78        ],79        retry_btn=None,80        undo_btn="↩ Undo",81        clear_btn="✕ Clear",82    )83 84demo.launch()85