Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,9 @@ user_prompt = '<|user|>\n'
|
|
28 |
assistant_prompt = '<|assistant|>\n'
|
29 |
prompt_suffix = "<|end|>\n"
|
30 |
|
|
|
|
|
|
|
31 |
|
32 |
def call_model(raw_image = None, text_input = None):
|
33 |
prompt = f"{user_prompt}<|image_1|>\n{text_input}{prompt_suffix}{assistant_prompt}"
|
@@ -63,10 +66,39 @@ def process(raw_image, prompt):
|
|
63 |
return memory_usage, model_response, execution_time_min
|
64 |
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
if __name__ == '__main__':
|
72 |
-
|
|
|
28 |
assistant_prompt = '<|assistant|>\n'
|
29 |
prompt_suffix = "<|end|>\n"
|
30 |
|
31 |
+
title_html = """
|
32 |
+
<h2> This space uses the model/microsoft/Phi-3.5-vision-instruct </h2>
|
33 |
+
"""
|
34 |
|
35 |
def call_model(raw_image = None, text_input = None):
|
36 |
prompt = f"{user_prompt}<|image_1|>\n{text_input}{prompt_suffix}{assistant_prompt}"
|
|
|
66 |
return memory_usage, model_response, execution_time_min
|
67 |
|
68 |
|
69 |
+
with gr.Blocks() as demo:
|
70 |
+
gr.HTML(title_html)
|
71 |
+
gr.Markdown("""
|
72 |
+
NOTES :
|
73 |
+
- The performance of this model is low since it runs on a CPU and a free space, it takes 1min minimum !.
|
74 |
+
- If the input text in not specified the model will describe the image, that will take more time
|
75 |
+
""")
|
76 |
+
with gr.Row():
|
77 |
+
with gr.Column():
|
78 |
+
_raw_image = gr.Image(type = 'pil')
|
79 |
+
user_input = gr.Textbox(label = "What do you want to ask?")
|
80 |
+
submit_btn = gr.Button(value = "Submit")
|
81 |
+
with gr.Column():
|
82 |
+
memory = gr.Textbox(label = "Memory usage")
|
83 |
+
results = gr.Textbox(label = "Model response")
|
84 |
+
exec_time = gr.Textbox(label = "Execution time (min)")
|
85 |
+
|
86 |
+
submit_btn.click(
|
87 |
+
process, inputs = [_raw_image, user_input], outputs = [memory, results, exec_time]
|
88 |
+
)
|
89 |
+
|
90 |
+
gr.Examples(
|
91 |
+
examples=[
|
92 |
+
["assets/img.jpg", 'after you can split horizontally the image into 6 rows, extract all text into JSON format. ignore "Au-dessous de Normal" and "Au-dessus de Normal"'],
|
93 |
+
["assets/cats.jpg", 'how many cats are here? and what are they doing ?'],
|
94 |
+
["assets/demo.jpg", 'is it night time ?'],
|
95 |
+
],
|
96 |
+
inputs=[_raw_image, user_input],
|
97 |
+
outputs=[memory, results, exec_time],
|
98 |
+
fn=process,
|
99 |
+
label="Examples",
|
100 |
+
)
|
101 |
+
|
102 |
|
103 |
if __name__ == '__main__':
|
104 |
+
demo.launch()
|