Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ def get_model_and_processor(model_id):
|
|
17 |
model = AutoModelForCausalLM.from_pretrained(
|
18 |
model_id,
|
19 |
trust_remote_code=True,
|
20 |
-
torch_dtype=torch.bfloat16
|
21 |
).cuda().eval()
|
22 |
processor = AutoProcessor.from_pretrained(
|
23 |
model_id,
|
@@ -25,7 +25,8 @@ def get_model_and_processor(model_id):
|
|
25 |
)
|
26 |
return model, processor
|
27 |
|
28 |
-
|
|
|
29 |
def run_example(image, text_input=None, model_id=model_name):
|
30 |
model, processor = get_model_and_processor(model_id)
|
31 |
prompt = f"{user_prompt}<|image_1|>\n{text_input}{prompt_suffix}{assistant_prompt}"
|
@@ -45,44 +46,7 @@ def run_example(image, text_input=None, model_id=model_name):
|
|
45 |
)[0]
|
46 |
return response
|
47 |
|
48 |
-
|
49 |
-
#output {
|
50 |
-
height: 500px;
|
51 |
-
overflow: auto;
|
52 |
-
border: 1px solid #ccc;
|
53 |
-
}
|
54 |
-
"""
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
with gr.Tab(label="Phi-3.5 Input"):
|
60 |
-
with gr.Row():
|
61 |
-
with gr.Column():
|
62 |
-
input_img = gr.Image(label="Input Picture")
|
63 |
-
model_selector = gr.Dropdown(
|
64 |
-
choices=[model_name],
|
65 |
-
label="Model",
|
66 |
-
value=model_name
|
67 |
-
)
|
68 |
-
text_input = gr.Textbox(label="Question")
|
69 |
-
submit_btn = gr.Button(value="Submit")
|
70 |
-
with gr.Column():
|
71 |
-
output_text = gr.Textbox(label="Output Text")
|
72 |
-
|
73 |
-
examples = [
|
74 |
-
["image1.jpeg", "What does this painting tell us explain in detail?"],
|
75 |
-
["image2.jpg", "What does this painting tell us explain in detail?"],
|
76 |
-
["image3.jpg", "Describe the scene in this picture."]
|
77 |
-
]
|
78 |
-
|
79 |
-
gr.Examples(
|
80 |
-
examples=examples,
|
81 |
-
inputs=[input_img, text_input],
|
82 |
-
examples_per_page=3
|
83 |
-
)
|
84 |
-
|
85 |
-
submit_btn.click(run_example, [input_img, text_input, model_selector], [output_text])
|
86 |
-
|
87 |
-
demo.queue()
|
88 |
-
demo.launch()
|
|
|
17 |
model = AutoModelForCausalLM.from_pretrained(
|
18 |
model_id,
|
19 |
trust_remote_code=True,
|
20 |
+
torch_dtype=torch.bfloat16
|
21 |
).cuda().eval()
|
22 |
processor = AutoProcessor.from_pretrained(
|
23 |
model_id,
|
|
|
25 |
)
|
26 |
return model, processor
|
27 |
|
28 |
+
# Modified the spaces.GPU decorator usage
|
29 |
+
@spaces.GPU(memory=30) # Specify the GPU memory requirement in GB
|
30 |
def run_example(image, text_input=None, model_id=model_name):
|
31 |
model, processor = get_model_and_processor(model_id)
|
32 |
prompt = f"{user_prompt}<|image_1|>\n{text_input}{prompt_suffix}{assistant_prompt}"
|
|
|
46 |
)[0]
|
47 |
return response
|
48 |
|
49 |
+
# Rest of your code remains the same until demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
# Modified launch parameters
|
52 |
+
demo.launch(share=True, server_name="0.0.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|