import os import oss2 import requests import gradio as gr import clipdrop def translateEN(zh): result = requests.post( "https://api-free.deepl.com/v2/translate", params={ "auth_key": "e8b4d428-ada5-3f8d-f965-bad01e8a06c1:fx", "target_lang": "EN-US", "text": zh}) return result.json()["translations"][0]["text"] def process_text(prompt): print("输入的文本: \n", prompt) prompt_trans = translateEN(prompt) print("prompt: \n", prompt_trans) image_path = clipdrop.text_to_image(prompt_trans) # 使用阿里云OSS SDK上传图像到OSS存储桶 # 配置您的 OSS Bucket 信息 bucket_name = 'codejoyai-static' endpoint = 'http://oss-cn-beijing.aliyuncs.com' # 创建 OSS 客户端实例 auth = oss2.Auth('LTAI5tKa6jkMstCMDhrs2uMe', '402dwLJ3rsXOGcrYbMwNc2tyQnqeMe') bucket = oss2.Bucket(auth, endpoint, bucket_name) # 指定目录路径和文件名 directory = 'aigc-202308/' filename = os.path.basename(image_path) # 上传文件到指定目录 bucket.put_object_from_file(directory + filename, image_path) img_url = "https://codejoyai-static.oss-cn-beijing.aliyuncs.com" + "/" + directory + filename print(img_url) return img_url iface = gr.Interface(fn=process_text, inputs="text", outputs="image") # iface.queue(concurrency_count=1) iface.launch(enable_queue=True)