the-future-dev commited on
Commit
337ae31
1 Parent(s): 3f375a2

first commit

Browse files
Files changed (2) hide show
  1. app.py +2 -3
  2. kosmos.py +2 -9
app.py CHANGED
@@ -2,10 +2,9 @@ import streamlit as st
2
  from PIL import Image
3
  import kosmos
4
 
5
- kosmos.load_model()
6
- st.title('KOSMOS2 Model Evaluation')
7
 
8
- uploaded_file = st.file_uploader("Choose an image...", type="jpg")
9
 
10
  if uploaded_file is not None:
11
  try:
 
2
  from PIL import Image
3
  import kosmos
4
 
5
+ st.title('KOSMOS2 Chat box')
 
6
 
7
+ uploaded_file = st.file_uploader("Pick an image...", type="jpg")
8
 
9
  if uploaded_file is not None:
10
  try:
kosmos.py CHANGED
@@ -4,17 +4,10 @@ from os import path
4
  from torchvision.transforms import ToTensor
5
 
6
  model_id = "microsoft/kosmos-2-patch14-224"
7
- model = None
8
- processor = None
9
-
10
- def load_model():
11
- global model, processor
12
- model = AutoModelForVision2Seq.from_pretrained(model_id)
13
- processor = AutoProcessor.from_pretrained(model_id)
14
 
15
  def single_image_classification(image, prompt="", max_new_tokens=30):
16
- if model is None or processor is None:
17
- load_model()
18
  inputs = processor(text=prompt, images=image, return_tensors="pt")
19
 
20
  generated_ids = model.generate(
 
4
  from torchvision.transforms import ToTensor
5
 
6
  model_id = "microsoft/kosmos-2-patch14-224"
7
+ model = AutoModelForVision2Seq.from_pretrained(model_id)
8
+ processor = AutoProcessor.from_pretrained(model_id)
 
 
 
 
 
9
 
10
  def single_image_classification(image, prompt="", max_new_tokens=30):
 
 
11
  inputs = processor(text=prompt, images=image, return_tensors="pt")
12
 
13
  generated_ids = model.generate(