Spaces:
Runtime error
Runtime error
import openai | |
import gradio | |
openai.api_key = "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" | |
prompt="Entrez votre requête" | |
messages = [{"role": "system", "content": "You are Albert Einstein"}] | |
def CustomChatGPT(prompt): | |
messages.append({"role": "user", "content": prompt}) | |
response = openai.ChatCompletion.create( | |
model = "gpt-3.5-turbo", | |
messages = messages | |
) | |
ChatGPT_reply = response["choices"][0]["message"]["content"] | |
messages.append({"role": "assistant", "content": ChatGPT_reply}) | |
return ChatGPT_reply | |
import openai | |
import gradio | |
openai.api_key = "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" | |
prompt = "Entrez votre requête" | |
messages = [{"role": "system", "content": "You are Albert Einstein"}] | |
# Authentication function | |
def authenticate(username, password): | |
return username == "admin" and password == "pass1234" | |
def message_and_history(input, history): | |
history = history or [] | |
s = list(sum(history, ())) | |
s.append(input) | |
inp = ' '.join(s) | |
output = CustomChatGPT(inp) | |
history.append((input, output)) | |
return history, history | |
block = gradio.Blocks(theme=gradio.themes.Monochrome()) | |
with block: | |
gradio.Markdown("""<h1><center>ChatGPT | |
ChatBot with Gradio and OpenAI</center></h1> | |
""") | |
chatbot = gradio.Chatbot() | |
message = gradio.Textbox(placeholder=prompt) | |
state = gradio.State() | |
submit = gradio.Button("SEND") | |
submit.click(message_and_history, | |
inputs=[message, state], | |
outputs=[chatbot, state]) | |
# Add authentication to your Gradio app | |
app = gradio.Interface(fn=message_and_history, inputs=[message, state], outputs=[chatbot, state]) | |
# Provide authentication using the authenticate function | |
app.launch(auth=authenticate, debug=True) | |
app.launch(share=True) | |