-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
52 lines (40 loc) · 1.19 KB
/
app.py
File metadata and controls
52 lines (40 loc) · 1.19 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from flask import Flask, request, jsonify
import os
import openai
import json
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
app = Flask(__name__)
openai.api_key = OPENAI_API_KEY
@app.route('/hello', methods=['GET'])
def hello_flask():
return "hello, flask!"
@app.route('/image_verify', methods=['POST'])
def image_verify():
data = request.json
image_url = data.get('image')
print(image_url)
openai.api_key = OPENAI_API_KEY
client = openai.OpenAI(
api_key=OPENAI_API_KEY
)
response = client.chat.completions.create(
model="gpt-4-vision-preview",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "이 이미지가 쓰레기봉투의 이미지면 'success', 아니면 'fail'를 출력해줘."},
{
"type": "image_url",
"image_url": image_url
},
]
}
],
max_tokens=10
)
result = response.choices[0].message.content
print(result)
return jsonify({"result": result}) # success or fail
if __name__ == "__main__":
app.run()