AjithKSenthil commited on
Commit
6d39a16
·
verified ·
1 Parent(s): 91f2b1e

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +18 -13
chatbot.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import os
4
  import psycopg2
5
  from urllib.parse import urlparse
 
6
 
7
  # Initialize OpenAI client
8
  openai.api_key = os.getenv("OPENAI_API_KEY")
@@ -118,7 +119,7 @@ def store_survey_responses(user_id, responses):
118
  INSERT INTO survey_responses (user_id, responses)
119
  VALUES (%s, %s);
120
  '''
121
- cur.execute(insert_query, (user_id, responses))
122
  conn.commit()
123
  cur.close()
124
  conn.close()
@@ -176,18 +177,22 @@ def chatbot(input, state):
176
  return conversation, [user_id, messages]
177
 
178
  with gr.Blocks() as demo:
179
- username = gr.Textbox(label="Username")
180
- password = gr.Textbox(label="Password", type="password")
181
- login_button = gr.Button("Login")
182
- register_button = gr.Button("Register")
183
- auth_message = gr.Textbox(visible=False)
184
-
185
- chat_input = gr.Textbox(lines=7, label="Chat with AttachmentBot", visible=False)
186
- chat_output = gr.Textbox(label="Conversation", visible=False)
187
- state = gr.State([None, initial_messages.copy()])
188
-
189
- survey_inputs = create_survey_inputs()
190
- submit_survey = gr.Button("Submit Survey")
 
 
 
 
191
 
192
  def login(username, password):
193
  user_id = authenticate(username, password)
 
3
  import os
4
  import psycopg2
5
  from urllib.parse import urlparse
6
+ import json
7
 
8
  # Initialize OpenAI client
9
  openai.api_key = os.getenv("OPENAI_API_KEY")
 
119
  INSERT INTO survey_responses (user_id, responses)
120
  VALUES (%s, %s);
121
  '''
122
+ cur.execute(insert_query, (user_id, json.dumps(responses))) # Convert dictionary to JSON string
123
  conn.commit()
124
  cur.close()
125
  conn.close()
 
177
  return conversation, [user_id, messages]
178
 
179
  with gr.Blocks() as demo:
180
+ with gr.Row():
181
+ with gr.Column():
182
+ username = gr.Textbox(label="Username")
183
+ password = gr.Textbox(label="Password", type="password")
184
+ login_button = gr.Button("Login")
185
+ register_button = gr.Button("Register")
186
+ auth_message = gr.Textbox(visible=False)
187
+
188
+ with gr.Column():
189
+ survey_inputs = create_survey_inputs()
190
+ submit_survey = gr.Button("Submit Survey")
191
+
192
+ with gr.Column():
193
+ chat_input = gr.Textbox(lines=7, label="Chat with AttachmentBot", visible=False)
194
+ chat_output = gr.Textbox(label="Conversation", visible=False)
195
+ state = gr.State([None, initial_messages.copy()])
196
 
197
  def login(username, password):
198
  user_id = authenticate(username, password)