Spaces:
Runtime error
Runtime error
File size: 1,011 Bytes
2e6dee6 ea5c2f9 e045f7a 57775d5 a618bb4 2e6dee6 ea5c2f9 2e6dee6 ea5c2f9 a618bb4 e045f7a a618bb4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import os
import subprocess
from flask import Flask, render_template, Response, request, jsonify
from hello import hello
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)
|