from openai import OpenAI import gradio as gr import os chat_history=[] client = OpenAI( api_key=os.getenv('APIKEY'), organization=os.getenv('OPENAIORG'), ) assistant_id=os.getenv('ASSISTANTID1') thread = client.beta.threads.create() def validate_password(user_password): correct_password = os.getenv('MILPASSWORD') if user_password != correct_password: return False, "Incorrect password. Access denied." return True, "" #generates the ChatGPT call def generate_response(prompt, model_type): prompt=prompt messages = client.beta.threads.messages.create( thread_id=thread.id, role="user", content=prompt ) run = client.beta.threads.runs.create_and_poll( thread_id=thread.id, assistant_id=assistant_id, ) if run.status == 'completed': messages = client.beta.threads.messages.list( thread_id=thread.id ) message = client.beta.threads.messages.list( thread_id=thread.id ) response_text=message.data[0].content[0].text.value print(messages) print(prompt) return (response_text) def my_chatbot(input, history, user_password): text = "" valid, message = validate_password(user_password) if not valid: return [(input, message)], [], text model_type='gpt-4o-2024-05-13' history = history or [] output = generate_response(input, model_type) history.append((input, output)) return history, history, text with gr.Blocks(theme=gr.themes.Monochrome()) as demo: gr.Markdown("""