Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update chat_application/main.py
Browse files- chat_application/main.py +39 -0
chat_application/main.py
CHANGED
|
@@ -143,6 +143,7 @@ frobot = "projects/700531062565/locations/us-central1/endpoints/2951406418055397
|
|
| 143 |
client = MongoClient("mongodb://127.0.0.1:27017/")
|
| 144 |
db = client["huggingFaceData"]
|
| 145 |
rooms_collection = db.rooms
|
|
|
|
| 146 |
|
| 147 |
# List of fruits to choose display names from
|
| 148 |
FRUIT_NAMES = ["blueberry", "strawberry", "orange", "cherry"]
|
|
@@ -639,6 +640,16 @@ def choose():
|
|
| 639 |
"ended": False,
|
| 640 |
"ended_at": None
|
| 641 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 642 |
|
| 643 |
session['room'] = room_id
|
| 644 |
session['display_name'] = user_name
|
|
@@ -807,6 +818,34 @@ def handle_message(payload):
|
|
| 807 |
# Ask each bot for a response
|
| 808 |
socketio.start_background_task(ask_bot_round, room)
|
| 809 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 810 |
@socketio.on('disconnect')
|
| 811 |
def handle_disconnect():
|
| 812 |
room = session.get("room")
|
|
|
|
| 143 |
client = MongoClient("mongodb://127.0.0.1:27017/")
|
| 144 |
db = client["huggingFaceData"]
|
| 145 |
rooms_collection = db.rooms
|
| 146 |
+
feedback_collection = db.feedback
|
| 147 |
|
| 148 |
# List of fruits to choose display names from
|
| 149 |
FRUIT_NAMES = ["blueberry", "strawberry", "orange", "cherry"]
|
|
|
|
| 640 |
"ended": False,
|
| 641 |
"ended_at": None
|
| 642 |
})
|
| 643 |
+
# Create the new feedback in the database
|
| 644 |
+
feedback_collection.insert_one({
|
| 645 |
+
"_id": room_id,
|
| 646 |
+
# creation date/time
|
| 647 |
+
"created_at": datetime.utcnow(),
|
| 648 |
+
# user identity
|
| 649 |
+
"user_id": user_id,
|
| 650 |
+
# empty feedback history
|
| 651 |
+
"feedbacks": [],
|
| 652 |
+
})
|
| 653 |
|
| 654 |
session['room'] = room_id
|
| 655 |
session['display_name'] = user_name
|
|
|
|
| 818 |
# Ask each bot for a response
|
| 819 |
socketio.start_background_task(ask_bot_round, room)
|
| 820 |
|
| 821 |
+
|
| 822 |
+
@socketio.on('feedback_given')
|
| 823 |
+
def handle_message(payload):
|
| 824 |
+
room = session.get('room')
|
| 825 |
+
name = session.get('display_name')
|
| 826 |
+
if not room or not name:
|
| 827 |
+
return
|
| 828 |
+
|
| 829 |
+
text = payload.get("feedback", "").strip()
|
| 830 |
+
if not text:
|
| 831 |
+
return # ignore empty text
|
| 832 |
+
|
| 833 |
+
# Database-only message (with datetime)
|
| 834 |
+
db_feedback = {
|
| 835 |
+
"message": text,
|
| 836 |
+
"timestamp": datetime.utcnow()
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
+
print(db_feedback)
|
| 840 |
+
# Store the full version in the database
|
| 841 |
+
result = feedback_collection.update_one(
|
| 842 |
+
{"_id": room},
|
| 843 |
+
{"$push": {"feedback_responses": db_feedback}}
|
| 844 |
+
)
|
| 845 |
+
|
| 846 |
+
#LR TODO: add success/faillure msg and confirmation
|
| 847 |
+
|
| 848 |
+
|
| 849 |
@socketio.on('disconnect')
|
| 850 |
def handle_disconnect():
|
| 851 |
room = session.get("room")
|