dmedhi commited on
Commit
ab3ecd9
β€’
1 Parent(s): 721cfde
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. Dockerfile +18 -0
  3. README.md +5 -5
  4. app.py +46 -0
  5. requirements.txt +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ moondream filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ RUN chmod +x /app/moondream
17
+
18
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
README.md CHANGED
@@ -1,11 +1,11 @@
1
  ---
2
- title: Moondream
3
- emoji: 🐠
4
- colorFrom: purple
5
- colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
- license: mit
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Vlm Recognition
3
+ emoji: πŸ‘€
4
+ colorFrom: yellow
5
+ colorTo: gray
6
  sdk: docker
7
  pinned: false
8
+ license: apache-2.0
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import subprocess
3
+ from tempfile import NamedTemporaryFile
4
+
5
+ from fastapi import FastAPI, HTTPException
6
+ from pydantic import BaseModel
7
+
8
+ app = FastAPI()
9
+
10
+
11
+ # define request body
12
+ class RequestData(BaseModel):
13
+ prompt: str
14
+ image: str
15
+
16
+
17
+ @app.get("/")
18
+ def greet_json():
19
+ return {"Hello": "World!"}
20
+
21
+
22
+ @app.post("/query")
23
+ def query(data: RequestData):
24
+ prompt = data.prompt
25
+ image = data.image
26
+
27
+ try:
28
+ # decode base64 to image
29
+ image = base64.b64decode(image)
30
+
31
+ with NamedTemporaryFile(delete=True, suffix=".png") as temp_image:
32
+ temp_image.write(image)
33
+ temp_image.flush()
34
+
35
+ result = subprocess.run(
36
+ ["./moondream", "--prompt", prompt, "--image", temp_image.name],
37
+ capture_output=True,
38
+ text=True,
39
+ )
40
+
41
+ if result.returncode != 0:
42
+ raise Exception(result.stderr)
43
+
44
+ return {"response": result.stdout}
45
+ except Exception as e:
46
+ raise HTTPException(status_code=500, detail=str(e))
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ pydantic