ved1beta
commited on
Commit
·
dd39d5d
1
Parent(s):
821b34e
appready
Browse files
app.py
CHANGED
@@ -13,9 +13,9 @@ import torch
|
|
13 |
import spaces
|
14 |
|
15 |
model_id = "microsoft/Phi-3-vision-128k-instruct"
|
16 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="
|
17 |
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
18 |
-
model.to("
|
19 |
|
20 |
PLACEHOLDER = """
|
21 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
@@ -25,7 +25,7 @@ PLACEHOLDER = """
|
|
25 |
</div>
|
26 |
"""
|
27 |
|
28 |
-
@spaces.
|
29 |
def bot_streaming(message, history):
|
30 |
print(f'message is - {message}')
|
31 |
print(f'history is - {history}')
|
@@ -71,7 +71,7 @@ def bot_streaming(message, history):
|
|
71 |
print(f"prompt is -\n{conversation}")
|
72 |
prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
|
73 |
image = Image.open(image)
|
74 |
-
inputs = processor(prompt, image, return_tensors="pt").to("
|
75 |
|
76 |
streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,})
|
77 |
generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024, do_sample=False, temperature=0.0, eos_token_id=processor.tokenizer.eos_token_id,)
|
|
|
13 |
import spaces
|
14 |
|
15 |
model_id = "microsoft/Phi-3-vision-128k-instruct"
|
16 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cpu", trust_remote_code=True, torch_dtype="auto")
|
17 |
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
18 |
+
model.to("cpu")
|
19 |
|
20 |
PLACEHOLDER = """
|
21 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
|
|
25 |
</div>
|
26 |
"""
|
27 |
|
28 |
+
@spaces.CPU
|
29 |
def bot_streaming(message, history):
|
30 |
print(f'message is - {message}')
|
31 |
print(f'history is - {history}')
|
|
|
71 |
print(f"prompt is -\n{conversation}")
|
72 |
prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
|
73 |
image = Image.open(image)
|
74 |
+
inputs = processor(prompt, image, return_tensors="pt").to("cpu")
|
75 |
|
76 |
streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,})
|
77 |
generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024, do_sample=False, temperature=0.0, eos_token_id=processor.tokenizer.eos_token_id,)
|