|
|
import streamlit as st |
|
|
import openai |
|
|
from PIL import Image |
|
|
import io |
|
|
|
|
|
|
|
|
openai.api_key = "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" |
|
|
|
|
|
st.title("照片内容分析 App") |
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("上传一张照片", type=["jpg", "jpeg", "png"]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
|
|
image = Image.open(uploaded_file) |
|
|
st.image(image, caption="上传的照片", use_column_width=True) |
|
|
|
|
|
|
|
|
img_byte_arr = io.BytesIO() |
|
|
image.save(img_byte_arr, format='PNG') |
|
|
img_byte_arr = img_byte_arr.getvalue() |
|
|
|
|
|
|
|
|
response = openai.Image.create( |
|
|
prompt="Analyze the contents of this image", |
|
|
n=1, |
|
|
size="100x100", |
|
|
response_format="json" |
|
|
) |
|
|
|
|
|
|
|
|
st.subheader("照片内容分析结果") |
|
|
st.write(response['choices'][0]['text']) |
|
|
else: |
|
|
st.write("请上传一张照片以进行分析。") |
|
|
|