import gradio as gr import requests # API调用函数 def call_api(user_input): url = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev" # 替换为你的API URL 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() # 返回API的响应 else: return f"Error: {response.status_code}" # 使用Gradio界面 iface = gr.Interface( fn=call_api, inputs="text", outputs="json", title="API 调用", description="输入文本并从API获取结果" ) iface.launch()