yichuan-huang commited on
Commit
8f054ed
·
1 Parent(s): c1d40d5
Files changed (4) hide show
  1. Dockerfile +2 -1
  2. app.py +0 -0
  3. classifier.py +0 -0
  4. utils.py +41 -0
Dockerfile CHANGED
@@ -5,12 +5,13 @@ RUN apt-get update && \
5
  curl \
6
  ca-certificates \
7
  procps \
 
8
  && apt-get clean \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
  RUN curl -fsSL https://ollama.com/install.sh | sh
12
 
13
- RUN pip install langchain langchain-ollama
14
 
15
  RUN ollama serve & \
16
  sleep 10 && \
 
5
  curl \
6
  ca-certificates \
7
  procps \
8
+ git \
9
  && apt-get clean \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
  RUN curl -fsSL https://ollama.com/install.sh | sh
13
 
14
+ RUN pip install ollama langchain langchain-ollama pillow
15
 
16
  RUN ollama serve & \
17
  sleep 10 && \
app.py ADDED
File without changes
classifier.py ADDED
File without changes
utils.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ from PIL import Image
3
+ import os
4
+ import tempfile
5
+
6
+
7
+ def encode_image_to_base64(image_path):
8
+ """
9
+ Encodes an image file to a base64 string.
10
+ Args:
11
+ image_path (str): The path to the image file.
12
+ Returns:
13
+ str: Base64 encoded string of the image.
14
+ """
15
+ with open(image_path, "rb") as image_file:
16
+ return base64.b64encode(image_file.read()).decode("utf-8")
17
+
18
+
19
+ def save_uploaded_file(uploaded_file):
20
+ """
21
+ Saves an uploaded file to a temporary location.
22
+ """
23
+ if not os.path.exists("temp"):
24
+ os.makedirs("temp")
25
+
26
+ temp_path = os.path.join("temp", uploaded_file.filename)
27
+ with open(temp_path, "wb") as f:
28
+ f.write(uploaded_file.getvalue())
29
+ return temp_path
30
+
31
+
32
+ def resize_image(image_path, max_size=(1024, 1024)):
33
+ """
34
+ Resizes an image to fit within the specified maximum size while maintaining aspect ratio.
35
+ Args:
36
+ image_path (str): The path to the image file.
37
+ max_size (tuple): The maximum width and height (width, height) for the resized image.
38
+ """
39
+ with Image.open(image_path) as img:
40
+ img.thumbnail(max_size, Image.Resampling.LANCZOS)
41
+ img.save(image_path)