Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,11 @@
|
|
1 |
-
import gradio as gr
|
2 |
import requests
|
3 |
-
import io
|
4 |
-
from PIL import Image
|
5 |
-
from dotenv import load_dotenv
|
6 |
-
import os
|
7 |
|
8 |
-
# 載入環境變數
|
9 |
-
load_dotenv()
|
10 |
-
|
11 |
-
# Hugging Face API 設定
|
12 |
API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/ukiyo-e-art"
|
13 |
-
headers = {"Authorization": "Bearer
|
14 |
-
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return image
|
22 |
-
except Exception as e:
|
23 |
-
return None
|
24 |
-
|
25 |
-
# 建立 Gradio 介面
|
26 |
-
iface = gr.Interface(
|
27 |
-
fn=generate_image,
|
28 |
-
inputs=gr.Textbox(label="請輸入圖像描述"),
|
29 |
-
outputs=gr.Image(label="生成的圖像"),
|
30 |
-
title="浮世繪風格圖像生成器",
|
31 |
-
description="輸入描述文字,生成浮世繪風格的圖像"
|
32 |
-
)
|
33 |
-
|
34 |
-
# 啟動應用
|
35 |
-
iface.launch()
|
|
|
|
|
1 |
import requests
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
3 |
API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/ukiyo-e-art"
|
4 |
+
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
|
5 |
+
|
6 |
+
def query(payload):
|
7 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
8 |
+
return response.content
|
9 |
+
image_bytes = query({
|
10 |
+
"inputs": "Astronaut riding a horse",
|
11 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|