Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,8 +13,14 @@ headers = {
|
|
13 |
"Authorization": f"Bearer {HF_API_KEY}"
|
14 |
}
|
15 |
|
16 |
-
def call_hf_api(api_url,
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
if response.status_code != 200:
|
19 |
raise Exception(f"Request failed with status {response.status_code}, {response.text}")
|
20 |
return response.json()
|
@@ -25,19 +31,15 @@ def process_image_with_api(image_path):
|
|
25 |
image_bytes = f.read()
|
26 |
|
27 |
# Prior Reduxモデルで事前処理
|
28 |
-
|
29 |
-
prior_response = call_hf_api(API_URL_PRIOR, prior_payload)
|
30 |
|
31 |
# FLUXモデルで画像生成
|
32 |
flux_payload = {
|
33 |
-
"
|
34 |
-
"
|
35 |
-
|
36 |
-
"num_inference_steps": 50,
|
37 |
-
"seed": 0, # 再現性のためのシード値
|
38 |
-
}
|
39 |
}
|
40 |
-
flux_response = call_hf_api(API_URL_FLUX, flux_payload)
|
41 |
|
42 |
# 生成された画像を取得
|
43 |
generated_image_url = flux_response.get("generated_image_url")
|
|
|
13 |
"Authorization": f"Bearer {HF_API_KEY}"
|
14 |
}
|
15 |
|
16 |
+
def call_hf_api(api_url, image_bytes, parameters=None):
|
17 |
+
# 画像データを multipart/form-data として送信
|
18 |
+
files = {
|
19 |
+
"file": ("image.png", image_bytes, "image/png"),
|
20 |
+
}
|
21 |
+
data = {"parameters": parameters} if parameters else {}
|
22 |
+
|
23 |
+
response = requests.post(api_url, headers=headers, files=files, data=data)
|
24 |
if response.status_code != 200:
|
25 |
raise Exception(f"Request failed with status {response.status_code}, {response.text}")
|
26 |
return response.json()
|
|
|
31 |
image_bytes = f.read()
|
32 |
|
33 |
# Prior Reduxモデルで事前処理
|
34 |
+
prior_response = call_hf_api(API_URL_PRIOR, image_bytes)
|
|
|
35 |
|
36 |
# FLUXモデルで画像生成
|
37 |
flux_payload = {
|
38 |
+
"guidance_scale": 2.5,
|
39 |
+
"num_inference_steps": 50,
|
40 |
+
"seed": 0, # 再現性のためのシード値
|
|
|
|
|
|
|
41 |
}
|
42 |
+
flux_response = call_hf_api(API_URL_FLUX, image_bytes, parameters=flux_payload)
|
43 |
|
44 |
# 生成された画像を取得
|
45 |
generated_image_url = flux_response.get("generated_image_url")
|