File size: 643 Bytes
34e9fcd
c779bb9
 
34e9fcd
019e7d3
 
 
 
 
 
 
 
d258d96
c779bb9
d258d96
019e7d3
 
 
 
 
 
 
 
 
 
 
 
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
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()