myraisza commited on
Commit
8648667
·
verified ·
1 Parent(s): d117be0

Upload 4 files

Browse files
greenangelica_secure_hfspace/README.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Hair Analyzer Green Angelica
2
+
3
+ Gradio app untuk analisa rambut via Hugging Face Inference API.
greenangelica_secure_hfspace/app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import requests
4
+ import base64
5
+ import os
6
+
7
+ def analyze_hair(name, phone, gender, city, image):
8
+ api_url = "https://api-inference.huggingface.co/models/microsoft/beit-base-patch16-224"
9
+ hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
10
+ headers = {"Authorization": f"Bearer {hf_token}"}
11
+
12
+ img_bytes = image.read()
13
+ encoded_image = base64.b64encode(img_bytes).decode("utf-8")
14
+ payload = { "inputs": encoded_image }
15
+
16
+ response = requests.post(api_url, headers=headers, json=payload)
17
+ if response.status_code != 200:
18
+ return "Gagal konek ke AI", "", "", "", ""
19
+
20
+ result = response.json()
21
+ label = result[0]["label"]
22
+ score = result[0]["score"] * 100
23
+
24
+ rekomendasi = "Gunakan paket lengkap Green Angelica"
25
+ if "Dry" in label: rekomendasi = "Gunakan Serum & Tonik Green Angelica"
26
+ elif "Oily" in label: rekomendasi = "Gunakan Shampo Green Angelica"
27
+
28
+ return (
29
+ f"Hasil: {label}",
30
+ f"Akurasi AI: {score:.2f}%",
31
+ f"Rekomendasi: {rekomendasi}",
32
+ "https://shopee.co.id/ga.greenangelica",
33
+ "https://wa.me/6285607761778?text=Halo%20Admin%2C%20saya%20ingin%20konsultasi%20masalah%20rambut"
34
+ )
35
+
36
+ demo = gr.Interface(
37
+ fn=analyze_hair,
38
+ inputs=[
39
+ gr.Textbox(label="Nama"),
40
+ gr.Textbox(label="No WhatsApp"),
41
+ gr.Radio(["Pria", "Wanita"], label="Jenis Kelamin"),
42
+ gr.Textbox(label="Kota"),
43
+ gr.Image(type="file", label="Upload Foto Rambut")
44
+ ],
45
+ outputs=[
46
+ gr.Textbox(label="Hasil AI"),
47
+ gr.Textbox(label="Kepercayaan"),
48
+ gr.Textbox(label="Saran Produk"),
49
+ gr.Textbox(label="Link Shopee"),
50
+ gr.Textbox(label="Link WA Konsultasi")
51
+ ],
52
+ title="Hair Analyzer Green Angelica",
53
+ description="Analisa jenis rambut dan rekomendasi produk Green Angelica via AI"
54
+ )
55
+
56
+ demo.launch()
greenangelica_secure_hfspace/logo green angelica.jpg ADDED
greenangelica_secure_hfspace/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ requests