Spaces:
Runtime error
Runtime error
Srinivasulu kethanaboina commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -109,14 +109,28 @@ def predict(message, history):
|
|
| 109 |
response_with_logo = f'<div class="response-with-logo">{logo_html}<div class="response-text">{response}</div></div>'
|
| 110 |
return response_with_logo
|
| 111 |
def save_chat_message(session_id, message_data):
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
# Define your Gradio chat interface function (replace with your actual logic)
|
| 116 |
def chat_interface(message, history,request: gr.Request):
|
| 117 |
try:
|
| 118 |
# Generate a unique session ID for this chat session
|
| 119 |
-
session_id = str(
|
| 120 |
|
| 121 |
# Process the user message and generate a response (your chatbot logic)
|
| 122 |
response = handle_query(message)
|
|
|
|
| 109 |
response_with_logo = f'<div class="response-with-logo">{logo_html}<div class="response-text">{response}</div></div>'
|
| 110 |
return response_with_logo
|
| 111 |
def save_chat_message(session_id, message_data):
|
| 112 |
+
# Reference based on sender's unique ID
|
| 113 |
+
sender_id = message_data['sender']
|
| 114 |
+
|
| 115 |
+
# Define the structure of the message
|
| 116 |
+
message_entry = {
|
| 117 |
+
"Message": message_data['message'],
|
| 118 |
+
"Response": message_data['response'],
|
| 119 |
+
"Timestamp": message_data['timestamp']
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
# Save data to Firebase using session ID and sender ID
|
| 123 |
+
ref = db.reference(f'/chat_history/{session_id}/{sender_id}')
|
| 124 |
+
|
| 125 |
+
# Push the new message to the sender's chat history
|
| 126 |
+
ref.push().set(message_entry)
|
| 127 |
+
|
| 128 |
|
| 129 |
# Define your Gradio chat interface function (replace with your actual logic)
|
| 130 |
def chat_interface(message, history,request: gr.Request):
|
| 131 |
try:
|
| 132 |
# Generate a unique session ID for this chat session
|
| 133 |
+
session_id = str(uuid.uuid4())
|
| 134 |
|
| 135 |
# Process the user message and generate a response (your chatbot logic)
|
| 136 |
response = handle_query(message)
|