ollama-server / app.py
DeathDaDev's picture
Add web interface and API endpoint for Ollama interaction.
e045f7a
raw
history blame
987 Bytes
import os
import subprocess
from flask import Flask, render_template, Response, request, jsonify
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html", logs_url="/logs", api_url="/api/generate")
@app.route("/logs")
def logs():
def stream_logs():
process = subprocess.Popen(["docker-compose", "logs", "-f", "ollama"], stdout=subprocess.PIPE)
for line in iter(process.stdout.readline, b''):
yield line.decode('utf-8')
return Response(stream_logs(), mimetype='text/plain')
@app.route("/api/generate", methods=["POST"])
def generate():
data = request.get_json()
prompt = data.get("prompt")
if not prompt:
return jsonify({"error": "Missing prompt"}), 400
# TODO: Implement logic to send prompt to Ollama and get response
response = "This is a placeholder response"
return jsonify({"response": response})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)