Srinivasulu kethanaboina commited on
Commit
bb0cb25
1 Parent(s): 389e31c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -102,13 +102,13 @@ def retrieve_history_and_redirect(cookies):
102
  [f"User: {entry['query']}\nBot: {entry['response']}" for entry in history_list]
103
  )
104
 
105
- # Prepare the message
106
  message = f"""
107
  Chat history:
108
  {history_str}
109
  """
110
 
111
- # Call the Gradio API
112
  result = client.predict(
113
  message=message,
114
  system_prompt="Summarize the text and provide client interest in 30-40 words in bullet points.",
@@ -121,11 +121,21 @@ def retrieve_history_and_redirect(cookies):
121
  )
122
 
123
  # Print the result for debugging
124
- print(result)
125
 
 
 
 
 
 
 
126
  # Send the result to the URL
127
- response = requests.post("https://redfernstech.com/api/receive_result", json={"result": result})
128
- print(response.status_code, response.text)
 
 
 
 
129
 
130
  # Define your Gradio chat interface function
131
  def chat_interface(message, history):
@@ -172,18 +182,18 @@ div.progress-text.svelte-z7cif2.meta-text {display: none;}
172
 
173
  # Use Gradio Blocks to wrap components
174
  with gr.Blocks(css=css) as demo:
175
- with gr.Row(): # Align horizontally in the same row
176
- with gr.Column(scale=8): # 80% for chat interface
177
- chat = gr.ChatInterface(chat_interface, clear_btn=None, undo_btn=None, retry_btn=None)
178
-
179
  with gr.Column(scale=2): # 20% for custom button
180
- redirect_button = gr.Button("Close Chat")
181
-
182
  # Connect the button with the function, and handle the redirection
183
- redirect_button.click(fn=retrieve_history_and_redirect, inputs=[gr.State()])
184
 
185
  # Add a JavaScript function to handle redirection after the Gradio event is processed
186
- redirect_button.click(fn=None, js="() => { window.open('https://redfernstech.com/chat-bot-test', '_blank'); }")
187
 
188
  # Launch the Gradio interface
189
  demo.launch()
 
102
  [f"User: {entry['query']}\nBot: {entry['response']}" for entry in history_list]
103
  )
104
 
105
+ # Prepare the message for summarization
106
  message = f"""
107
  Chat history:
108
  {history_str}
109
  """
110
 
111
+ # Call the Gradio API for summarization
112
  result = client.predict(
113
  message=message,
114
  system_prompt="Summarize the text and provide client interest in 30-40 words in bullet points.",
 
121
  )
122
 
123
  # Print the result for debugging
124
+ print(f"Summary: {result}")
125
 
126
+ # Prepare the data to be sent via POST request
127
+ data = {
128
+ "summary": result,
129
+ "timestamp": str(datetime.datetime.now())
130
+ }
131
+
132
  # Send the result to the URL
133
+ response = requests.post("https://redfernstech.com/api/receive_result", json=data)
134
+
135
+ # Debugging response status
136
+ print(f"POST request response: {response.status_code}, {response.text}")
137
+
138
+ return response.status_code, response.text
139
 
140
  # Define your Gradio chat interface function
141
  def chat_interface(message, history):
 
182
 
183
  # Use Gradio Blocks to wrap components
184
  with gr.Blocks(css=css) as demo:
185
+ chatbot = gr.Chatbot(placeholder="<strong>Your Personal Yes-Man</strong><br>Ask Me Anything")
186
+ with gr.Row(): # Align horizontally in the same line
187
+ with gr.Column(scale=8): # 80% for the input and submit button
188
+ submit_button = gr.ChatInterface(fn=chat_interface, chatbot=chatbot, clear_btn=None, undo_btn=None, retry_btn=None)
189
  with gr.Column(scale=2): # 20% for custom button
190
+ custom_button = gr.Button("Close Chat")
191
+
192
  # Connect the button with the function, and handle the redirection
193
+ custom_button.click(fn=retrieve_history_and_redirect, inputs=[gr.State()])
194
 
195
  # Add a JavaScript function to handle redirection after the Gradio event is processed
196
+ custom_button.click(fn=None, js="() => { window.open('https://redfernstech.com/chat-bot-test', '_blank'); }")
197
 
198
  # Launch the Gradio interface
199
  demo.launch()