import gradio as gr from openai import OpenAI # Modal endpoint — keep deployed: modal deploy philosopher_modal.py MODAL_URL = "https://mark-gentry--qwen3-philosopher-serve.modal.run/v1" MODEL_ID = "qwen3-philosopher" client = OpenAI(base_url=MODAL_URL, api_key="unused") SYSTEM_PROMPT = ( "You are a philosopher trained to reason carefully and rigorously. " "When given a question or position, construct a structured argument — " "identify the key claims, examine the assumptions, consider serious objections, " "and defend or revise your position in light of them. " "Do not merely summarise what philosophers have said. Reason." ) def chat(message, history): messages = [{"role": "system", "content": SYSTEM_PROMPT}] for human, assistant in history: messages.append({"role": "user", "content": human}) messages.append({"role": "assistant", "content": assistant}) messages.append({"role": "user", "content": message}) response = "" try: stream = client.chat.completions.create( model=MODEL_ID, messages=messages, max_tokens=1500, temperature=0.7, stream=True, ) for chunk in stream: delta = chunk.choices[0].delta.content or "" response += delta yield response except Exception as e: yield f"Model unavailable — the philosopher is thinking elsewhere. ({e})" with gr.Blocks( theme=gr.themes.Base( primary_hue="indigo", font=[gr.themes.GoogleFont("Georgia"), "serif"], ), title="The Philosopher — TunedAI Labs", css=""" .gradio-container { max-width: 800px; margin: auto; } .chat-message { font-size: 15px; line-height: 1.7; } footer { display: none; } """ ) as demo: gr.Markdown(""" # The Philosopher A 27B model fine-tuned to reason philosophically — not retrieve positions. Ask it anything in philosophy of mind, ethics, metaphysics, or epistemology. It will construct an argument, not a summary. *Built on Qwen3.6-27B · DPO fine-tuned · [TunedAI Labs](https://tunedailabs.com)* """) chatbot = gr.ChatInterface( fn=chat, chatbot=gr.Chatbot(height=500, elem_classes=["chat-message"]), textbox=gr.Textbox( placeholder="Ask a philosophical question or state a position to argue against...", container=False, ), examples=[ "Is consciousness reducible to physical processes?", "Does personal identity persist through radical change?", "Can free will exist in a deterministic universe?", "What is the strongest argument against moral realism?", "Argue against Chalmers' hard problem of consciousness.", ], retry_btn=None, undo_btn="↩ Undo", clear_btn="✕ Clear", ) demo.launch()