import gradio as gr
import subprocess

def run_ollama_prompt(prompt, model="deepseek-r1:1.5b"):
    """Runs a prompt using Ollama CLI and returns the response."""
    command = ["ollama", "run", model, prompt]

    try:
        result = subprocess.run(command, capture_output=True, text=True, check=True, encoding="utf-8")
        return result.stdout.strip()
    except subprocess.CalledProcessError as e:
        return f"Error running Ollama: {e}"

# Gradio Interface
def generate_response(prompt):
    return run_ollama_prompt(prompt)

with gr.Blocks() as app:
    gr.Markdown("# DeepSeek 1.5B Chat App")

    with gr.Row():
        prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Type something...")
    
    with gr.Row():
        submit_button = gr.Button("Generate Response")

    response_output = gr.Textbox(label="Response", interactive=False)

    submit_button.click(fn=generate_response, inputs=prompt_input, outputs=response_output)


app.launch()
