Update app.py
Browse files
app.py
CHANGED
|
@@ -30,11 +30,26 @@ model = AutoModelForVision2Seq.from_pretrained(model_id, torch_dtype="auto", dev
|
|
| 30 |
|
| 31 |
@spaces.GPU
|
| 32 |
def stream_chat(message: Dict[str, str], history: list):
|
|
|
|
| 33 |
# {'text': 'what is this', 'files': ['image-xxx.jpg']}
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
image = Image.open(message["files"][0])
|
| 38 |
pixel_values = processor(images=[image], return_tensors="pt").to(model.device)["pixel_values"]
|
| 39 |
|
| 40 |
conversation = []
|
|
|
|
| 30 |
|
| 31 |
@spaces.GPU
|
| 32 |
def stream_chat(message: Dict[str, str], history: list):
|
| 33 |
+
# Turn 1:
|
| 34 |
# {'text': 'what is this', 'files': ['image-xxx.jpg']}
|
| 35 |
+
# []
|
| 36 |
+
|
| 37 |
+
# Turn 2:
|
| 38 |
+
# {'text': 'continue?', 'files': []}
|
| 39 |
+
# [[('image-xxx.jpg',), None], ['what is this', 'a image.']]
|
| 40 |
+
|
| 41 |
+
if len(message["files"]) != 0:
|
| 42 |
+
image_path = message["files"][0]
|
| 43 |
+
|
| 44 |
+
if isinstance(history[0][0], tuple):
|
| 45 |
+
image_path = history[0][0][0]
|
| 46 |
+
history.pop(0)
|
| 47 |
+
|
| 48 |
+
if image_path is not None:
|
| 49 |
+
image = Image.open(image_path)
|
| 50 |
+
else:
|
| 51 |
+
image = Image.new("RGB", (100, 100), (255, 255, 255))
|
| 52 |
|
|
|
|
| 53 |
pixel_values = processor(images=[image], return_tensors="pt").to(model.device)["pixel_values"]
|
| 54 |
|
| 55 |
conversation = []
|