-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageUpload.py
More file actions
46 lines (37 loc) ยท 1.33 KB
/
imageUpload.py
File metadata and controls
46 lines (37 loc) ยท 1.33 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
from dotenv import load_dotenv
import os
from openai import OpenAI
import streamlit as st
from PIL import Image
import base64
import requests
load_dotenv()
img = None
base64_image = None
api_key=os.environ.get("OPENAI_API_KEY")
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"),
)
st.title("KoJaem's bot ๐")
uploaded_file = st.file_uploader('์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ ํ์ธ์.', type=['png', 'jpg', 'jpeg'])
if uploaded_file is not None: # ํ์ผ์ ๋ฃ์ ๊ฒฝ์ฐ์๋ง ์คํ ํจ
base64_image = base64.b64encode(uploaded_file.read()).decode('utf-8')
img = Image.open(uploaded_file)
st.image(img, caption='์
๋ก๋๋ ์ด๋ฏธ์ง', use_column_width=True)
keyword = st.text_input('ํ์ํ๊ฒ์ ์
๋ ฅํด์ฃผ์ธ์.')
if st.button('์์ฒญํ๊ธฐ'):
with st.spinner('์ด๋ฏธ์ง ์์ฑ์ค...'):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {
"model": "gpt-4o",
"image": base64_image,
}
response = requests.post("https://api.openai.com/v1/images/variations", headers=headers, json=payload)
if response.status_code == 200:
result = response.json()
st.write(result)
else:
st.write("Error:", response.status_code, response.text)