yeecin commited on
Commit
86c445c
1 Parent(s): f928d96

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -13
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import gradio as gr
2
  from transformers import BlipProcessor, BlipForConditionalGeneration
3
  from PIL import Image
4
- from transformers import pipeline
5
 
 
6
  processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
7
  model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
8
 
@@ -12,23 +12,14 @@ def generate_caption(image):
12
  description = processor.decode(outputs[0], skip_special_tokens=True)
13
  return description
14
 
15
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
16
-
17
- def predict(input_img):
18
- predictions = pipeline(input_img)
19
- return input_img, {p["label"]: p["score"] for p in predictions}
20
-
21
  gradio_app = gr.Interface(
22
- # predict,
23
- # inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
24
- # outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
25
- # title="Hot Dog? Or Not?",
26
  fn=generate_caption,
27
- inputs=gr.inputs.Image(type="pil"),
28
  outputs="text",
29
  title="图片描述生成器",
30
  description="上传一张图片,生成相应的描述。"
31
  )
32
 
33
  if __name__ == "__main__":
34
- gradio_app.launch()
 
1
  import gradio as gr
2
  from transformers import BlipProcessor, BlipForConditionalGeneration
3
  from PIL import Image
 
4
 
5
+ # 加载模型和处理器
6
  processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
7
  model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
8
 
 
12
  description = processor.decode(outputs[0], skip_special_tokens=True)
13
  return description
14
 
15
+ # 创建Gradio接口
 
 
 
 
 
16
  gradio_app = gr.Interface(
 
 
 
 
17
  fn=generate_caption,
18
+ inputs=gr.Image(type="pil"),
19
  outputs="text",
20
  title="图片描述生成器",
21
  description="上传一张图片,生成相应的描述。"
22
  )
23
 
24
  if __name__ == "__main__":
25
+ gradio_app.launch()