Obaws commited on
Commit
976d7e9
1 Parent(s): 88033d6

chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +59 -0
chatbot.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio
3
+
4
+ openai.api_key = "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"
5
+ prompt="Entrez votre requête"
6
+ messages = [{"role": "system", "content": "You are Albert Einstein"}]
7
+
8
+
9
+
10
+ def CustomChatGPT(prompt):
11
+ messages.append({"role": "user", "content": prompt})
12
+ response = openai.ChatCompletion.create(
13
+ model = "gpt-3.5-turbo",
14
+ messages = messages
15
+ )
16
+ ChatGPT_reply = response["choices"][0]["message"]["content"]
17
+ messages.append({"role": "assistant", "content": ChatGPT_reply})
18
+ return ChatGPT_reply
19
+
20
+ import openai
21
+ import gradio
22
+
23
+ openai.api_key = "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"
24
+ prompt = "Entrez votre requête"
25
+ messages = [{"role": "system", "content": "You are Albert Einstein"}]
26
+
27
+ # Authentication function
28
+ def authenticate(username, password):
29
+ return username == "admin" and password == "pass1234"
30
+
31
+
32
+
33
+ def message_and_history(input, history):
34
+ history = history or []
35
+ s = list(sum(history, ()))
36
+ s.append(input)
37
+ inp = ' '.join(s)
38
+ output = CustomChatGPT(inp)
39
+ history.append((input, output))
40
+ return history, history
41
+ block = gradio.Blocks(theme=gradio.themes.Monochrome())
42
+ with block:
43
+ gradio.Markdown("""<h1><center>ChatGPT
44
+ ChatBot with Gradio and OpenAI</center></h1>
45
+ """)
46
+ chatbot = gradio.Chatbot()
47
+ message = gradio.Textbox(placeholder=prompt)
48
+ state = gradio.State()
49
+ submit = gradio.Button("SEND")
50
+ submit.click(message_and_history,
51
+ inputs=[message, state],
52
+ outputs=[chatbot, state])
53
+ # Add authentication to your Gradio app
54
+ app = gradio.Interface(fn=message_and_history, inputs=[message, state], outputs=[chatbot, state])
55
+
56
+ # Provide authentication using the authenticate function
57
+ app.launch(auth=authenticate, debug=True)
58
+
59
+ app.launch(share=True)