Spaces:
Runtime error
Runtime error
Lambang
commited on
Commit
·
f50765e
1
Parent(s):
bb9d3db
using API
Browse files
__pycache__/data_preprocess.cpython-39.pyc
CHANGED
Binary files a/__pycache__/data_preprocess.cpython-39.pyc and b/__pycache__/data_preprocess.cpython-39.pyc differ
|
|
__pycache__/file_processing.cpython-39.pyc
CHANGED
Binary files a/__pycache__/file_processing.cpython-39.pyc and b/__pycache__/file_processing.cpython-39.pyc differ
|
|
__pycache__/hairstyle_recommendation.cpython-39.pyc
ADDED
Binary file (2.42 kB). View file
|
|
__pycache__/train_pred.cpython-39.pyc
CHANGED
Binary files a/__pycache__/train_pred.cpython-39.pyc and b/__pycache__/train_pred.cpython-39.pyc differ
|
|
gender_class.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
API_URL = "https://api-inference.huggingface.co/models/rizvandwiki/gender-classification-2"
|
4 |
+
headers = {"Authorization": "Bearer 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"}
|
5 |
+
|
6 |
+
def query(filename):
|
7 |
+
with open(filename, "rb") as f:
|
8 |
+
data = f.read()
|
9 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
10 |
+
return response.json()
|
11 |
+
|
12 |
+
output = query("test.jpg")
|
13 |
+
|
14 |
+
print(output)
|
main.py
CHANGED
@@ -12,8 +12,12 @@ from fastapi.responses import JSONResponse
|
|
12 |
from pydantic import BaseModel
|
13 |
import subprocess
|
14 |
from hairstyle_recommendation import HairstyleRecommendation
|
|
|
15 |
|
|
|
16 |
app = FastAPI()
|
|
|
|
|
17 |
public_url = "https://lambang0902-test-space.hf.space"
|
18 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
19 |
|
@@ -58,6 +62,12 @@ from train_pred import TrainPred
|
|
58 |
data_processor = DataProcessing()
|
59 |
data_train_pred = TrainPred()
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
import random
|
62 |
def preprocessing(filepath):
|
63 |
folder_path = './static/temporary'
|
@@ -107,9 +117,9 @@ async def root():
|
|
107 |
# API UNTUK MELAKUKAN PROSES PREDIKSI
|
108 |
# -------------------------------------------------------------------------
|
109 |
# Use a pipeline as a high-level helper
|
110 |
-
from transformers import pipeline
|
111 |
|
112 |
-
pipe = pipeline("image-classification", model="rizvandwiki/gender-classification-2")
|
113 |
|
114 |
@app.post('/upload/file',tags=["Predicting"])
|
115 |
async def upload_file(picture: UploadFile):
|
@@ -147,7 +157,7 @@ def get_images():
|
|
147 |
bentuk, persentase = data_train_pred.prediction(selected_model)
|
148 |
|
149 |
# Gender classification
|
150 |
-
gender_classify =
|
151 |
output_gender = max(gender_classify, key=lambda x: x['score'])['label']
|
152 |
|
153 |
|
|
|
12 |
from pydantic import BaseModel
|
13 |
import subprocess
|
14 |
from hairstyle_recommendation import HairstyleRecommendation
|
15 |
+
import requests
|
16 |
|
17 |
+
# A FUCKING PI
|
18 |
app = FastAPI()
|
19 |
+
API_URL = "https://api-inference.huggingface.co/models/rizvandwiki/gender-classification-2"
|
20 |
+
headers = {"Authorization": "Bearer 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"}
|
21 |
public_url = "https://lambang0902-test-space.hf.space"
|
22 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
23 |
|
|
|
62 |
data_processor = DataProcessing()
|
63 |
data_train_pred = TrainPred()
|
64 |
|
65 |
+
def get_gender(filename):
|
66 |
+
with open(filename, "rb") as f:
|
67 |
+
data = f.read()
|
68 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
69 |
+
return response.json()
|
70 |
+
|
71 |
import random
|
72 |
def preprocessing(filepath):
|
73 |
folder_path = './static/temporary'
|
|
|
117 |
# API UNTUK MELAKUKAN PROSES PREDIKSI
|
118 |
# -------------------------------------------------------------------------
|
119 |
# Use a pipeline as a high-level helper
|
120 |
+
# from transformers import pipeline
|
121 |
|
122 |
+
# pipe = pipeline("image-classification", model="rizvandwiki/gender-classification-2")
|
123 |
|
124 |
@app.post('/upload/file',tags=["Predicting"])
|
125 |
async def upload_file(picture: UploadFile):
|
|
|
157 |
bentuk, persentase = data_train_pred.prediction(selected_model)
|
158 |
|
159 |
# Gender classification
|
160 |
+
gender_classify = get_gender('./static/result_upload0.jpg')
|
161 |
output_gender = max(gender_classify, key=lambda x: x['score'])['label']
|
162 |
|
163 |
|