Spaces:
Sleeping
Sleeping
File size: 932 Bytes
9c7f230 4dd54ba 70d04d1 4dd54ba 1ffb5a3 70d04d1 4dd54ba 70d04d1 4dd54ba 70d04d1 1ffb5a3 70d04d1 9c7f230 1ffb5a3 70d04d1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
import requests
import io
from PIL import Image
from dotenv import load_dotenv
import os
# 載入環境變數
load_dotenv()
# Hugging Face API 設定
API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/ukiyo-e-art"
headers = {"Authorization": "Bearer hf_MySpaceToken"}
def generate_image(prompt):
try:
# 呼叫 Hugging Face API
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
# 轉換回應為圖像
image = Image.open(io.BytesIO(response.content))
return image
except Exception as e:
return None
# 建立 Gradio 介面
iface = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(label="請輸入圖像描述"),
outputs=gr.Image(label="生成的圖像"),
title="浮世繪風格圖像生成器",
description="輸入描述文字,生成浮世繪風格的圖像"
)
# 啟動應用
iface.launch() |