Spaces:
Running
on
Zero
Running
on
Zero
SunderAli17
commited on
Commit
•
e337c90
1
Parent(s):
00d2a60
Update app.py
Browse files
app.py
CHANGED
@@ -15,21 +15,29 @@ processors = {
|
|
15 |
"microsoft/Phi-3.5-vision-instruct": AutoProcessor.from_pretrained("microsoft/Phi-3.5-vision-instruct", trust_remote_code=True)
|
16 |
}
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
kwargs = {}
|
21 |
kwargs['torch_dtype'] = torch.bfloat16
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
@spaces.GPU
|
28 |
def run_example(image, text_input=None, model_id="microsoft/Phi-3.5-vision-instruct"):
|
29 |
model = models[model_id]
|
30 |
processor = processors[model_id]
|
31 |
|
32 |
-
prompt = f"{
|
33 |
image = Image.fromarray(image).convert("RGB")
|
34 |
|
35 |
inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
|
@@ -43,16 +51,20 @@ def run_example(image, text_input=None, model_id="microsoft/Phi-3.5-vision-instr
|
|
43 |
clean_up_tokenization_spaces=False)[0]
|
44 |
return response
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
"""
|
53 |
-
|
54 |
-
|
55 |
-
gr.Markdown(DESCRIPTION)
|
56 |
with gr.Tab(label="Phi-3.5 Input"):
|
57 |
with gr.Row():
|
58 |
with gr.Column():
|
|
|
15 |
"microsoft/Phi-3.5-vision-instruct": AutoProcessor.from_pretrained("microsoft/Phi-3.5-vision-instruct", trust_remote_code=True)
|
16 |
}
|
17 |
|
18 |
+
MARKDOWN = """
|
19 |
+
This demo utilizes <a href="https://huggingface.co/microsoft/Phi-3.5-vision-instruct">Phi-3.5-Vision Instruct</a> by @Microsoft.
|
20 |
+
|
21 |
+
Try out with different images and generate captions. Do provide your feedback.
|
22 |
+
|
23 |
+
Model Card is acquired from <a href="https://huggingface.co/microsoft/Phi-3.5-vision-instruct"> Microsoft's Phi Vision Instruct</a>
|
24 |
+
|
25 |
+
**Demo by [Sunder Ali Khowaja](https://sander-ali.github.io) - [X](https://x.com/SunderAKhowaja) -[Github](https://github.com/sander-ali) -[Hugging Face](https://huggingface.co/SunderAli17)**
|
26 |
+
"""
|
27 |
|
28 |
kwargs = {}
|
29 |
kwargs['torch_dtype'] = torch.bfloat16
|
30 |
|
31 |
+
promptu = '<|user|>\n'
|
32 |
+
prompta = '<|assistant|>\n'
|
33 |
+
prompts = "<|end|>\n"
|
34 |
|
35 |
@spaces.GPU
|
36 |
def run_example(image, text_input=None, model_id="microsoft/Phi-3.5-vision-instruct"):
|
37 |
model = models[model_id]
|
38 |
processor = processors[model_id]
|
39 |
|
40 |
+
prompt = f"{promptu}<|image_1|>\n{text_input}{prompts}{prompta}"
|
41 |
image = Image.fromarray(image).convert("RGB")
|
42 |
|
43 |
inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
|
|
|
51 |
clean_up_tokenization_spaces=False)[0]
|
52 |
return response
|
53 |
|
54 |
+
theme = gr.themes.Soft(
|
55 |
+
font=[gr.themes.GoogleFont('Pacifico'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
|
56 |
+
)
|
57 |
+
js_func = """
|
58 |
+
function refresh() {
|
59 |
+
const url = new URL(window.location);
|
60 |
+
if (url.searchParams.get('__theme') !== 'dark') {
|
61 |
+
url.searchParams.set('__theme', 'dark');
|
62 |
+
window.location.href = url.href;
|
63 |
+
}
|
64 |
+
}
|
65 |
"""
|
66 |
+
with gr.Blocks(js=js_func, theme=theme) as demo:
|
67 |
+
gr.Markdown(MARKDOWN)
|
|
|
68 |
with gr.Tab(label="Phi-3.5 Input"):
|
69 |
with gr.Row():
|
70 |
with gr.Column():
|