46. /image 경로로 이미지 파일 서빙 연습
Video
준비 중
Note
test.py
test.py
from flask import Flask, render_template, Response, send_file
app = Flask(__name__)
@app.route("/")
def index():
title = "OpenAI API Agent School"
return render_template('index.html', title=title)
@app.route("/api/hello")
def hello_api():
return "Hello, World!"
@app.route("/api/chat")
def chat_api():
text = "Hello, World!"
def generate():
import time
for char in text:
yield char
time.sleep(1)
return Response(generate(), mimetype='text/event-stream')
@app.route('/image/<image_name>')
def serve_image(image_name):
return send_file(
f"test/{image_name}",
mimetype=f'image/{image_name.split(".")[-1]}',
as_attachment=False
)
if __name__ == "__main__":
app.run(host="0.0.0.0")