ake178178 commited on
Commit
ad7ff87
·
verified ·
1 Parent(s): 2df4993

Create backup.txt

Browse files
Files changed (1) hide show
  1. backup.txt +27 -0
backup.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import BlipProcessor, BlipForConditionalGeneration
3
+ from PIL import Image
4
+
5
+ # 加载BLIP模型和处理器
6
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
7
+ model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
8
+
9
+ st.title("图像描述生成器")
10
+ st.write("使用摄像头拍照并生成图像的描述。")
11
+
12
+ # 使用Streamlit的camera_input来获取用户摄像头输入
13
+ image_data = st.camera_input("请使用摄像头拍照")
14
+
15
+ if image_data is not None:
16
+ # 将图像数据转换为PIL图像
17
+ image = Image.open(image_data)
18
+
19
+ # 显示拍摄的图像
20
+ st.image(image, caption="拍摄的图像", use_column_width=True)
21
+
22
+ # 生成图像描述
23
+ inputs = processor(image, return_tensors="pt")
24
+ out = model.generate(**inputs)
25
+ caption = processor.decode(out[0], skip_special_tokens=True)
26
+
27
+ st.write(f"图像描述: {caption}")