import gradio as gr | |
import io | |
from PIL import Image | |
# gr.Interface.load("models/runwayml/stable-diffusion-v1-5").launch() | |
import requests | |
API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5" | |
headers = {"Authorization": "Bearer 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"} | |
def query(payload): | |
response = requests.post(API_URL, headers=headers, json=payload) | |
image = Image.open(io.BytesIO(response.content)) | |
return image | |
# 创建Gradio界面 | |
iface = gr.Interface( | |
fn=query, | |
inputs="text", | |
outputs="image", | |
# live=True, | |
title="text to image" | |
) | |
# 启动Gradio应用 | |
iface.launch() |