seu-ebers commited on
Commit
2bab99e
·
1 Parent(s): 2a0a961
Files changed (2) hide show
  1. app.py +17 -2
  2. requirements.txt +4 -1
app.py CHANGED
@@ -1,11 +1,20 @@
1
  import streamlit as st
2
- from transformers import pipeline
 
 
3
  from PIL import Image
4
 
 
5
  pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
6
 
7
  st.title("Hot Dog? Or Not?")
8
 
 
 
 
 
 
 
9
  file_name = st.file_uploader("Upload a hot dog candidate image")
10
 
11
  if file_name is not None:
@@ -17,4 +26,10 @@ if file_name is not None:
17
 
18
  col2.header("Probabilities")
19
  for p in predictions:
20
- col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import torch
3
+ import spaces
4
+ from transformers import pipeline, AutoModelForCausalLM, AutoProcessor
5
  from PIL import Image
6
 
7
+
8
  pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
9
 
10
  st.title("Hot Dog? Or Not?")
11
 
12
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
13
+
14
+ image_model_id = "microsoft/git-large-coco"
15
+ image_processor = AutoProcessor.from_pretrained(image_model_id)
16
+ image_model = AutoModelForCausalLM.from_pretrained(image_model_id).to(device)
17
+
18
  file_name = st.file_uploader("Upload a hot dog candidate image")
19
 
20
  if file_name is not None:
 
26
 
27
  col2.header("Probabilities")
28
  for p in predictions:
29
+ col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
30
+
31
+ pixel_values = image_processor(images=image, return_tensors="pt").pixel_values
32
+
33
+ generated_ids = image_model.generate(pixel_values=pixel_values, max_length=50)
34
+ generated_caption = image_processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
35
+ print(generated_caption)
requirements.txt CHANGED
@@ -1,3 +1,6 @@
1
  transformers
2
  torch
3
- accelerate
 
 
 
 
1
  transformers
2
  torch
3
+ accelerate
4
+ streamlit~=1.30.0
5
+ pillow~=10.2.0
6
+ requests~=2.31.0