|
import gradio as gr |
|
import requests |
|
|
|
|
|
def call_api(user_input): |
|
url = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev" |
|
headers = {"Authorization": "Bearer YOUR_TOKEN"} |
|
params = {"query": user_input} |
|
|
|
response = requests.get(url, headers=headers, params=params) |
|
if response.status_code == 200: |
|
return response.json() |
|
else: |
|
return f"Error: {response.status_code}" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=call_api, |
|
inputs="text", |
|
outputs="json", |
|
title="API 调用", |
|
description="输入文本并从API获取结果" |
|
) |
|
|
|
iface.launch() |
|
|