yeshavyas27
commited on
Commit
•
cb660f6
1
Parent(s):
5747245
Update app.py
Browse files
app.py
CHANGED
@@ -11,13 +11,13 @@ parser = argparse.ArgumentParser()
|
|
11 |
parser.add_argument("--cpu", action="store_true", help="Use CPU for computation")
|
12 |
args = parser.parse_args([])
|
13 |
|
14 |
-
DEVICE = "cpu"
|
15 |
-
DTYPE = torch.float32
|
16 |
LATEST_REVISION = "2024-05-20"
|
17 |
-
|
18 |
tokenizer = AutoTokenizer.from_pretrained("vikhyatk/moondream2", revision=LATEST_REVISION)
|
19 |
moondream = AutoModelForCausalLM.from_pretrained(
|
20 |
-
|
21 |
).to(device=DEVICE)
|
22 |
|
23 |
moondream.eval()
|
@@ -94,5 +94,4 @@ with gr.Blocks() as demo:
|
|
94 |
prompt.submit(answer_question, [img, prompt], output)
|
95 |
output.change(process_answer, [img, output], ann, show_progress=False)
|
96 |
|
97 |
-
|
98 |
-
demo.queue().launch(debug=False)
|
|
|
11 |
parser.add_argument("--cpu", action="store_true", help="Use CPU for computation")
|
12 |
args = parser.parse_args([])
|
13 |
|
14 |
+
DEVICE = "cuda" if torch.cuda.is_available() and not args.cpu else "cpu" # Determine device based on availability and argument
|
15 |
+
DTYPE = torch.float32 if DEVICE == "cpu" else torch.float16 # CPU doesn't support float16
|
16 |
LATEST_REVISION = "2024-05-20"
|
17 |
+
MODEL_ID = "yeshavyas27/moondream-ft"
|
18 |
tokenizer = AutoTokenizer.from_pretrained("vikhyatk/moondream2", revision=LATEST_REVISION)
|
19 |
moondream = AutoModelForCausalLM.from_pretrained(
|
20 |
+
MODEL_ID, trust_remote_code=True, torch_dtype=DTYPE
|
21 |
).to(device=DEVICE)
|
22 |
|
23 |
moondream.eval()
|
|
|
94 |
prompt.submit(answer_question, [img, prompt], output)
|
95 |
output.change(process_answer, [img, output], ann, show_progress=False)
|
96 |
|
97 |
+
demo.queue().launch(debug=True)
|
|