Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,14 +27,15 @@ model = AutoModelForCausalLM.from_pretrained("StanfordAIMI/CheXagent-8b", torch_
|
|
27 |
|
28 |
@spaces.GPU
|
29 |
def generate(image, prompt):
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
images = [image]
|
33 |
|
34 |
-
# Prepare inputs
|
35 |
inputs = processor(images=images, text=f" USER: <s>{prompt} ASSISTANT: <s>", return_tensors="pt").to(device=device, dtype=dtype)
|
36 |
|
37 |
-
# Generate the findings
|
38 |
output = model.generate(**inputs, generation_config=generation_config)[0]
|
39 |
response = processor.tokenizer.decode(output, skip_special_tokens=True)
|
40 |
return response
|
@@ -51,7 +52,11 @@ with gr.Blocks() as demo:
|
|
51 |
output_text_custom = gr.Textbox(label="Response")
|
52 |
|
53 |
def custom_generate(image, prompt):
|
54 |
-
|
|
|
|
|
|
|
|
|
55 |
|
56 |
generate_button_custom.click(fn=custom_generate, inputs=[image_input_custom, prompt_input_custom], outputs=output_text_custom)
|
57 |
|
|
|
27 |
|
28 |
@spaces.GPU
|
29 |
def generate(image, prompt):
|
30 |
+
if hasattr(image_input, "read"):
|
31 |
+
image = Image.open(io.BytesIO(image_input.read())).convert("RGB")
|
32 |
+
else:
|
33 |
+
image = image
|
34 |
+
|
35 |
images = [image]
|
36 |
|
|
|
37 |
inputs = processor(images=images, text=f" USER: <s>{prompt} ASSISTANT: <s>", return_tensors="pt").to(device=device, dtype=dtype)
|
38 |
|
|
|
39 |
output = model.generate(**inputs, generation_config=generation_config)[0]
|
40 |
response = processor.tokenizer.decode(output, skip_special_tokens=True)
|
41 |
return response
|
|
|
52 |
output_text_custom = gr.Textbox(label="Response")
|
53 |
|
54 |
def custom_generate(image, prompt):
|
55 |
+
if isinstance(image, str) and os.path.exists(image):
|
56 |
+
with open(image, 'rb') as file:
|
57 |
+
return generate(file, prompt)
|
58 |
+
else:
|
59 |
+
return generate(image, prompt)
|
60 |
|
61 |
generate_button_custom.click(fn=custom_generate, inputs=[image_input_custom, prompt_input_custom], outputs=output_text_custom)
|
62 |
|