HawkeyeHS commited on
Commit
7efe748
·
1 Parent(s): 2e9a741

Add application file

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. app.py +57 -0
  3. requirements.txt +56 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["gunicorn","-b", "0.0.0.0:7860", "main:app"]
12
+
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import warnings
3
+ from transformers import AutoModelForImageClassification, AutoFeatureExtractor
4
+ import torch
5
+ warnings.filterwarnings("ignore")
6
+
7
+ import json
8
+ from flask_cors import CORS
9
+ from flask import Flask, request, Response
10
+
11
+ import numpy as np
12
+ from PIL import Image
13
+ import requests
14
+
15
+ from io import BytesIO
16
+
17
+ os.environ["CUDA_VISIBLE_DEVICES"] = ""
18
+
19
+ app = Flask(__name__)
20
+ cors = CORS(app)
21
+
22
+ global MODEL
23
+ global CLASSES
24
+
25
+
26
+ @app.route("/", methods=["GET"])
27
+ def default():
28
+ return json.dumps({"Hello I am Chitti": "Speed 1 Terra Hertz, Memory 1 Zeta Byte"})
29
+
30
+
31
+ @app.route("/predict", methods=["GET"])
32
+ def predict():
33
+ feature_extractor = AutoFeatureExtractor.from_pretrained('carbon225/vit-base-patch16-224-hentai')
34
+ model = AutoModelForImageClassification.from_pretrained('carbon225/vit-base-patch16-224-hentai')
35
+ src = request.args.get("src")
36
+ print(f"{src=}")
37
+ response = requests.get(src)
38
+ print(f"{response=}")
39
+ try:
40
+ image = Image.open(BytesIO(response.content))
41
+ image = image.resize((128, 128))
42
+ image.save("new.jpg")
43
+ encoding = feature_extractor(image.convert("RGB"), return_tensors="pt")
44
+ with torch.no_grad():
45
+ outputs = model(**encoding)
46
+ logits = outputs.logits
47
+
48
+ predicted_class_idx = logits.argmax(-1).item()
49
+ print(model.config.id2label[predicted_class_idx])
50
+ # Return the predictions
51
+ response=json.dumps({"class": model.config.id2label[predicted_class_idx]})
52
+ response = Response(response)
53
+ response.headers['Content-Security-Policy'] = "script-src 'self' render.com;" # Modify this CSP as needed
54
+ return response
55
+ except:
56
+ return json.dumps({"Uh oh": "We are down"})
57
+
requirements.txt ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ blinker==1.7.0
2
+ bs4==0.0.1
3
+ certifi==2023.11.17
4
+ charset-normalizer==3.3.2
5
+ click==8.1.7
6
+ filelock==3.13.1
7
+ Flask==3.0.0
8
+ Flask-Cors==4.0.0
9
+ fsspec==2023.12.2
10
+ huggingface-hub==0.20.1
11
+ idna==3.6
12
+ importlib-metadata==7.0.0
13
+ itsdangerous==2.1.2
14
+ Jinja2==3.1.2
15
+ markdownify==0.11.6
16
+ MarkupSafe==2.1.3
17
+ mpmath==1.3.0
18
+ networkx==3.2.1
19
+ numpy==1.26.2
20
+ nvidia-cublas-cu12==12.1.3.1
21
+ nvidia-cuda-cupti-cu12==12.1.105
22
+ nvidia-cuda-nvrtc-cu12==12.1.105
23
+ nvidia-cuda-runtime-cu12==12.1.105
24
+ nvidia-cudnn-cu12==8.9.2.26
25
+ nvidia-cufft-cu12==11.0.2.54
26
+ nvidia-curand-cu12==10.3.2.106
27
+ nvidia-cusolver-cu12==11.4.5.107
28
+ nvidia-cusparse-cu12==12.1.0.106
29
+ nvidia-nccl-cu12==2.18.1
30
+ nvidia-nvjitlink-cu12==12.3.101
31
+ nvidia-nvtx-cu12==12.1.105
32
+ outcome==1.2.0
33
+ packaging==23.2
34
+ perplexity-api @ git+https://gitlab.com/robowaifudev/perplexity-api@0baebed39beeedc13e6281af5505f4c4221fdb5f
35
+ Pillow==10.1.0
36
+ PySocks==1.7.1
37
+ PyYAML==6.0.1
38
+ regex==2023.10.3
39
+ requests==2.31.0
40
+ safetensors==0.4.1
41
+ selenium==4.12.0
42
+ sortedcontainers==2.4.0
43
+ sympy==1.12
44
+ tokenizers==0.15.0
45
+ torch==2.1.2
46
+ tqdm==4.66.1
47
+ transformers==4.36.2
48
+ trio==0.22.2
49
+ trio-websocket==0.10.4
50
+ triton==2.1.0
51
+ typing_extensions==4.9.0
52
+ urllib3==2.1.0
53
+ Werkzeug==3.0.1
54
+ wsproto==1.2.0
55
+ zipp==3.17.0
56
+ gunicorn