Spaces:
Sleeping
Sleeping
File size: 638 Bytes
6395a16 827a624 3a76f1c 4248527 6395a16 e9bb3ab 3a76f1c 4248527 3a76f1c 827a624 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from flask import Flask, request, Response
from waitress import serve
import requests
import os
app = Flask(__name__)
OLLAMA_API_URL = "http://localhost:11434"
def generate(data):
with requests.post(f"{OLLAMA_API_URL}/api/chat", json=data, stream=True) as r:
for line in r.iter_lines():
if line:
yield line.decode('utf-8') + '\n'
@app.route('/chat', methods=['POST'])
def chat():
data = request.get_json(silent=True)
return Response(generate(data), mimetype='text/plain')
if __name__ == '__main__':
port = int(os.environ.get('PORT', 7860))
serve(app, host='0.0.0.0', port=port) |