第三弹来了!!!nvidia免费SD3 api 转 openai格式对接 openwebui

第一弹:nvidia白嫖sd3和llama3.1
第二弹:oneapi设置使用llama3.1

代码claude随便糊的,佬们不要笑话


from flask import Flask, request, jsonify
import requests
import base64
from io import BytesIO
from datetime import datetime
from flask_cors import CORS
app = Flask(__name__)
CORS(app)  # 启用CORS支持

# NVIDIA API URL 和 API Key
NVIDIA_URL = "https://ai.api.nvidia.com/v1/genai/stabilityai/stable-diffusion-3-medium"
NVIDIA_API_KEY = ""  # 使用你自己的 NVIDIA API 密钥


@app.route('/v1/images/generations', methods=['POST'])
def translate_request():
    data = request.json
    prompt = data.get('prompt')

    nvidia_payload = {
        "prompt": prompt,
        "cfg_scale": 5,
        "aspect_ratio": "16:9",
        "seed": 0,
        "steps": 50,
        "negative_prompt": ""
    }

    headers = {
        "Authorization": f"Bearer {NVIDIA_API_KEY}",
        "Content-Type": "application/json"
    }

    # 请求 NVIDIA API
    response = requests.post(NVIDIA_URL, headers=headers, json=nvidia_payload)
    response.raise_for_status()
    response_body = response.json()


    # 构造响应
    adapted_response = {
        "created": int(datetime.now().timestamp()),
        "data": [
            {
                "revised_prompt":"xxxxxxx",
                "b64_json": response_body['image']
            }
        ]
    }

    return jsonify(adapted_response)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5001)

食用教程:

  1. 服务器开放5001端口
    2.填入key
    3.持久化运行脚本 命令:nohup python3 your_script.py > output.log 2>&1 &
    4.openwebui填入url使用,密钥随便填

完结 撒花

23 个赞

感谢分享

1 个赞

精华神贴软件分享

这个SD貌似消耗的积分不少哦 :rofl:

1 个赞

c 就完了!
R佬起的好早

1 个赞

感谢

1 个赞

太强了!!!

感谢分享:fire:

感谢

好厉害

大帅哥来啦~~~~

来了宝贝

感谢分享

大佬强!

厉害

感谢佬

点赞

赞哇

2 个赞