Ulaş Dilek commited on
Commit
b13202a
1 Parent(s): 95c4e90

added user sessions

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -3,6 +3,7 @@ from dotenv import load_dotenv
3
  import os
4
  import anthropic
5
  import openai
 
6
  from util import ClaudeCompletion, GPTCompletion
7
 
8
  gr.close_all()
@@ -40,20 +41,18 @@ def chatWithGPT(chatHistory):
40
  return chatHistory
41
 
42
  with gr.Blocks() as demo:
43
- chatHistory = []
44
- gptsTurn = True
45
 
46
- def startConversation(prompt):
47
- global chatHistory, gptsTurn
48
  # nextBtn.interactive = False
49
  chatHistory = []
50
  startNewChat(prompt, chatHistory)
51
  # nextBtn.interactive = True
52
  gptsTurn = False
53
- return chatHistory
54
 
55
- def nextResponse():
56
- global gptsTurn
57
  # nextBtn.interactive = False
58
  if (gptsTurn):
59
  chatWithGPT(chatHistory)
@@ -61,7 +60,7 @@ with gr.Blocks() as demo:
61
  chatWithClaude(chatHistory)
62
  gptsTurn = not gptsTurn
63
  # nextBtn.interactive = True
64
- return chatHistory
65
 
66
  context = gr.Textbox(label="Context",
67
  placeholder="Set the context for two LLMs to chat with each other",
@@ -74,11 +73,11 @@ with gr.Blocks() as demo:
74
  ["A person is interested in Formula 1 and asks questions about the sport",
75
  "A little child wants to understand how planes fly",
76
  "You are a young indie game dev searching for ideas about their next strategy game",
77
- "You are an old irish man is interested in medieval european history"]
78
  , context)
79
  # nextBtn.interactive = False
80
- start_button.click(startConversation, context, chatbot, scroll_to_output=True, show_progress=True)
81
- nextBtn.click(nextResponse, None, chatbot, scroll_to_output=True, show_progress=True)
82
 
83
  try:
84
  demo.launch()
 
3
  import os
4
  import anthropic
5
  import openai
6
+ from uuid import uuid4
7
  from util import ClaudeCompletion, GPTCompletion
8
 
9
  gr.close_all()
 
41
  return chatHistory
42
 
43
  with gr.Blocks() as demo:
44
+ chatState = gr.State([])
45
+ gptsTurnState = gr.State(True)
46
 
47
+ def startConversation(prompt, gptsTurn):
 
48
  # nextBtn.interactive = False
49
  chatHistory = []
50
  startNewChat(prompt, chatHistory)
51
  # nextBtn.interactive = True
52
  gptsTurn = False
53
+ return chatHistory, chatHistory, gptsTurn
54
 
55
+ def nextResponse(chatHistory, gptsTurn):
 
56
  # nextBtn.interactive = False
57
  if (gptsTurn):
58
  chatWithGPT(chatHistory)
 
60
  chatWithClaude(chatHistory)
61
  gptsTurn = not gptsTurn
62
  # nextBtn.interactive = True
63
+ return chatHistory, chatHistory, gptsTurn
64
 
65
  context = gr.Textbox(label="Context",
66
  placeholder="Set the context for two LLMs to chat with each other",
 
73
  ["A person is interested in Formula 1 and asks questions about the sport",
74
  "A little child wants to understand how planes fly",
75
  "You are a young indie game dev searching for ideas about their next strategy game",
76
+ "You are an old irish man interested in medieval european history"]
77
  , context)
78
  # nextBtn.interactive = False
79
+ start_button.click(startConversation, [context, gptsTurnState], [chatbot, chatState, gptsTurnState], scroll_to_output=True, show_progress=True)
80
+ nextBtn.click(nextResponse, [chatState, gptsTurnState], [chatbot, chatState, gptsTurnState], scroll_to_output=True, show_progress=True)
81
 
82
  try:
83
  demo.launch()