import os import openai import gradio as gr openai.api_key = "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" start_sequence = "\nAI:" restart_sequence = "\nHuman: " prompt_txt = "输入你的问题" prompt_img = "输入你的图像提示词" messages = [ {"role": "system", "content": "you are a very useful assistant"}, ] def openai_create(input): user_message = {"role": "user", "content": input} messages.append(user_message) completion = openai.ChatCompletion.create( model="gpt-3.5-turbo-16k", messages=messages, ) completion = completion.choices[0].message.content messages.append({"role": "assistant", "content": completion}) return completion def chatgpt_image(input, image_size, history,image_input): completion = openai.Image.create( prompt=input, n=1, size=image_size ) return completion.data[0]['url'], history, "" def chatgpt_chat(input, history,input_text): history = history or [] output = openai_create(input) history.append((input, output)) return history, history, "" def clear(input,output): history = [] input = '' output = '' return "","","" block = gr.Blocks() with gr.Blocks() as block: gr.Markdown("""