Jonas Wiesli commited on
Commit
7fe812c
1 Parent(s): c8a9da6

test chat interface

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -5,7 +5,27 @@ import openai
5
  openai.api_key = "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"
6
 
7
 
8
- def generate(firstmessage):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  completion = openai.ChatCompletion.create(
10
  model="gpt-3.5-turbo",
11
  messages=[
@@ -31,6 +51,3 @@ def generate(firstmessage):
31
  )
32
  return completion.choices[0].message.content
33
 
34
-
35
- iface = gr.Interface(fn=generate, inputs="text", outputs="text")
36
- iface.launch()
 
5
  openai.api_key = "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"
6
 
7
 
8
+ with gr.Blocks() as iface:
9
+ chatbot = gr.Chatbot()
10
+ msg = gr.Textbox()
11
+
12
+ def user(user_message, history):
13
+ return "", history + [[user_message, None]]
14
+
15
+ def bot(history):
16
+ # bot_message = generateAIMessage(history)
17
+ bot_message = "test"
18
+ history[-1][1] = bot_message
19
+ print(history)
20
+ return history
21
+
22
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
23
+ bot, chatbot, chatbot
24
+ )
25
+
26
+ iface.launch()
27
+
28
+ def generateAIMessage(history):
29
  completion = openai.ChatCompletion.create(
30
  model="gpt-3.5-turbo",
31
  messages=[
 
51
  )
52
  return completion.choices[0].message.content
53