#!/usr/bin/env python # encoding: utf-8 import gradio as gr from datasets import load_dataset from PIL import Image import re import os import requests import threading import base64 import io sem = threading.Semaphore() def infer(prompt, negative, scale): try: url = os.environ.get('SERVICE_URL', 'https://modelbest.cn/') sem.acquire() resp = requests.post(url, headers={ "X-Model-Best-Model": "viscpm-paint-balance", "X-Model-Best-Trace-ID": "test-trace", }, json={ "question": prompt, "negative_prompt": negative, "num_images_per_prompt": 4, }) sem.release() resp = resp.json() images = resp['data']['response'] images = [Image.open(io.BytesIO(base64.b64decode(encoded_image))).convert("RGB") for encoded_image in images] return images except Exception as e: print(e) return [] with gr.Blocks() as demo: gr.Markdown('