Update app.py
Browse files
app.py
CHANGED
@@ -30,21 +30,22 @@ model.generation_config.eos_token_id = processor.tokenizer.eos_token_id
|
|
30 |
|
31 |
@spaces.GPU(duration=120)
|
32 |
def krypton(input, history):
|
|
|
|
|
|
|
33 |
if input["files"]:
|
34 |
-
print("
|
35 |
image_path = input["files"][-1]["path"] if isinstance(input["files"][-1], dict) else input["files"][-1]
|
|
|
36 |
else:
|
37 |
image_path = None
|
38 |
for hist in history:
|
39 |
if isinstance(hist[0], tuple):
|
40 |
-
|
41 |
|
42 |
if not image_path:
|
43 |
gr.Error("You need to upload an image for Krypton to work.")
|
44 |
return
|
45 |
-
|
46 |
-
prompt = f"user\n\n<image>\n{input['text']}\nassistant\n\n"
|
47 |
-
print("Made the prompt")
|
48 |
|
49 |
try:
|
50 |
image = Image.open(image_path)
|
@@ -54,6 +55,10 @@ def krypton(input, history):
|
|
54 |
gr.Error("Failed to open the image.")
|
55 |
return
|
56 |
|
|
|
|
|
|
|
|
|
57 |
try:
|
58 |
inputs = processor(prompt, images=image, return_tensors='pt').to('cuda', torch.float16)
|
59 |
print(f"Processed inputs: {inputs}")
|
@@ -62,7 +67,6 @@ def krypton(input, history):
|
|
62 |
gr.Error("Failed to process the inputs.")
|
63 |
return
|
64 |
|
65 |
-
|
66 |
# Streamer
|
67 |
print('About to init streamer')
|
68 |
streamer = TextIteratorStreamer(processor.tokenizer, skip_special_tokens=False, skip_prompt=True)
|
@@ -77,7 +81,7 @@ def krypton(input, history):
|
|
77 |
)
|
78 |
|
79 |
thread = threading.Thread(target=model.generate, kwargs=generation_kwargs)
|
80 |
-
print('
|
81 |
thread.start()
|
82 |
|
83 |
buffer = ""
|
|
|
30 |
|
31 |
@spaces.GPU(duration=120)
|
32 |
def krypton(input, history):
|
33 |
+
print(f"Input: {input}") # Debug input
|
34 |
+
print(f"History: {history}") # Debug history
|
35 |
+
|
36 |
if input["files"]:
|
37 |
+
print("Found the image\n")
|
38 |
image_path = input["files"][-1]["path"] if isinstance(input["files"][-1], dict) else input["files"][-1]
|
39 |
+
print(f"Image path: {image_path}")
|
40 |
else:
|
41 |
image_path = None
|
42 |
for hist in history:
|
43 |
if isinstance(hist[0], tuple):
|
44 |
+
image_path = hist[0][0]
|
45 |
|
46 |
if not image_path:
|
47 |
gr.Error("You need to upload an image for Krypton to work.")
|
48 |
return
|
|
|
|
|
|
|
49 |
|
50 |
try:
|
51 |
image = Image.open(image_path)
|
|
|
55 |
gr.Error("Failed to open the image.")
|
56 |
return
|
57 |
|
58 |
+
# Adding more context to the prompt with a placeholder for the image
|
59 |
+
prompt = f"user: Here is an image and a question about it.\n<image>{input['text']}\nassistant: "
|
60 |
+
print("Made the prompt")
|
61 |
+
|
62 |
try:
|
63 |
inputs = processor(prompt, images=image, return_tensors='pt').to('cuda', torch.float16)
|
64 |
print(f"Processed inputs: {inputs}")
|
|
|
67 |
gr.Error("Failed to process the inputs.")
|
68 |
return
|
69 |
|
|
|
70 |
# Streamer
|
71 |
print('About to init streamer')
|
72 |
streamer = TextIteratorStreamer(processor.tokenizer, skip_special_tokens=False, skip_prompt=True)
|
|
|
81 |
)
|
82 |
|
83 |
thread = threading.Thread(target=model.generate, kwargs=generation_kwargs)
|
84 |
+
print('Thread about to start')
|
85 |
thread.start()
|
86 |
|
87 |
buffer = ""
|