Csplk commited on
Commit
d31818b
β€’
1 Parent(s): 201e079

Delete batchlessapp.py

Browse files
Files changed (1) hide show
  1. batchlessapp.py +0 -63
batchlessapp.py DELETED
@@ -1,63 +0,0 @@
1
- import spaces
2
- import torch
3
- import re
4
- import gradio as gr
5
- from threading import Thread
6
- from transformers import TextIteratorStreamer, AutoTokenizer, AutoModelForCausalLM
7
-
8
- #import subprocess
9
- #subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
10
-
11
- if torch.cuda.is_available():
12
- device, dtype = "cuda", torch.float16
13
- else:
14
- device, dtype = "cpu", torch.float32
15
-
16
-
17
- model_id = "vikhyatk/moondream2"
18
- revision = "2024-04-02"
19
- tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
20
- moondream = AutoModelForCausalLM.from_pretrained(
21
- model_id, trust_remote_code=True, revision=revision
22
- ).to(device=device, dtype=dtype)
23
- moondream.eval()
24
-
25
-
26
- @spaces.GPU(duration=10)
27
- def answer_question(img, prompt):
28
- image_embeds = moondream.encode_image(img)
29
- streamer = TextIteratorStreamer(tokenizer, skip_special_tokens=True)
30
- thread = Thread(
31
- target=moondream.answer_question,
32
- kwargs={
33
- "image_embeds": image_embeds,
34
- "question": prompt,
35
- "tokenizer": tokenizer,
36
- "streamer": streamer,
37
- },
38
- )
39
- thread.start()
40
-
41
- buffer = ""
42
- for new_text in streamer:
43
- buffer += new_text
44
- yield buffer.strip()
45
-
46
-
47
- with gr.Blocks() as demo:
48
- gr.Markdown(
49
- """
50
- # πŸŒ” moondream2
51
- A tiny vision language model. [GitHub](https://github.com/vikhyat/moondream)
52
- """
53
- )
54
- with gr.Row():
55
- prompt = gr.Textbox(label="Input", value="Describe this image.", scale=4)
56
- submit = gr.Button("Submit")
57
- with gr.Row():
58
- img = gr.Image(type="pil", label="Upload an Image")
59
- output = gr.TextArea(label="Response")
60
- submit.click(answer_question, [img, prompt], output)
61
- prompt.submit(answer_question, [img, prompt], output)
62
-
63
- demo.queue().launch()