revi13 commited on
Commit
bb5430e
·
verified ·
1 Parent(s): 4155842

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -45
app.py CHANGED
@@ -1,49 +1,12 @@
1
-
2
- import os
3
- from huggingface_hub import login, hf_hub_download
4
-
5
- # ✅ トークン取得 & ログイン(重要)
6
- hf_token = os.environ.get("HUGGINGFACE_HUB_TOKEN")
7
- if not hf_token:
8
- raise ValueError("環境変数 'HUGGINGFACE_HUB_TOKEN' が設定されていません。Spacesの Secrets に設定してください。")
9
- login(hf_token) # 必ず login() を呼び出す
10
-
11
  import gradio as gr
12
- from PIL import Image
13
- import base64
14
- import io
15
-
16
- # ✅ モデルファイルのダウンロード(token 明示)
17
- model_path = hf_hub_download(
18
- repo_id="revi13/ip-adapter-faceid-private",
19
- filename="ip-adapter-faceid-plusv2_sd15.bin",
20
- token=hf_token
21
- )
22
-
23
- # ===== 🧠 推論パイプラインの読み込み =====
24
- from pipeline import IPFacePlusV2Pipeline
25
- pipeline = IPFacePlusV2Pipeline(model_path)
26
-
27
- # ===== 🎨 画像生成関数 =====
28
- def generate_image(base64_image: str, prompt: str):
29
- try:
30
- image_data = base64.b64decode(base64_image.split(',')[-1])
31
- image = Image.open(io.BytesIO(image_data)).convert("RGB")
32
- output = pipeline.generate(image, prompt)
33
- return output
34
- except Exception as e:
35
- return f"Error: {str(e)}"
36
 
37
- # ===== 🎛️ Gradio UI構築 =====
38
- demo = gr.Interface(
39
- fn=generate_image,
40
- inputs=[
41
- gr.Text(label="Base64 Image"),
42
- gr.Text(label="Prompt")
43
- ],
44
- outputs=gr.Image(type="pil"),
45
- allow_flagging="never"
46
- )
47
 
48
- # 🚀 Spacesでは __main__ チェック不要
49
  demo.launch()
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ def check_token():
5
+ token = os.environ.get("HUGGINGFACE_HUB_TOKEN")
6
+ if token:
7
+ return "✅ トークン取得成功(最初の10文字): " + token[:10] + "..."
8
+ else:
9
+ return "❌ トークンが取得できません。Spacesの Secrets に設定してください。"
 
 
 
 
10
 
11
+ demo = gr.Interface(fn=check_token, inputs=[], outputs="text")
12
  demo.launch()