Spaces:
Runtime error
Runtime error
Update main.py
Browse files788 unmodified lines78979079179279379479579679779879980011 unmodified lines812813814815816817818140 unmodified lines959960961962963964788 unmodified lines# Get roadmap dataroadmap_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id})if roadmap_data:return jsonify({'success': True, 'roadmapData': {'data': roadmap_data['data']}, 'activeDays': roadmap_data['activeDays']})else:return jsonify({'success': False})@app.route('/roadmap/history', methods=['GET'])@auth_userdef roadmapGetHistory():11 unmodified linesreturn jsonify({"error": "An error occurred"}), 500@app.route('/roadmapmodder', methods=['POST'])@auth_userdef roadmapmodder():140 unmodified linesreturn jsonify({'success': True})if __name__ == '__main__':app.run(debug=True, host='0.0.0.0')788 unmodified lines78979079179279379479579679779879911 unmodified lines811812813814815816140 unmodified lines9579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081788 unmodified lines# Get roadmap dataroadmap_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id})if roadmap_data:return jsonify({'success': True, 'roadmapData': {'data': roadmap_data['data']}, 'activeDays': roadmap_data['activeDays'], 'practice': roadmap_data['practice'], 'title': roadmap_data['title']})else:return jsonify({'success': False})@app.route('/roadmap/history', methods=['GET'])@auth_userdef roadmapGetHistory():11 unmodified linesreturn jsonify({"error": "An error occurred"}), 500@app.route('/roadmapmodder', methods=['POST'])@auth_userdef roadmapmodder():140 unmodified linesreturn jsonify({'success': True})@app.route('/problemgenerator', methods=['POST'])def problemgenerator():if request.method == 'POST':data = request.get_json()user_id = data.get('user_id')obj_id = data.get('_id')week_day = int(data.get('weekDay'))if data.get('type') == 1:query = data.get('query')prompt = '''Generate 5 Multiple Choice Questions with single correct answers and 4 options in the following format:[{"question": "What is that?", "options": {"1": "Option1", "2": "Option2", "3": "Option3", "4": "Option4"}, "answer" : {"3": "Option3"}, "explaination": "This is explaination."}, ... , {"question": "What is that?", "options": {"0": "Option1", "1": "Option2", "3": "Option3", "4": "Option4"}, "answer" : {"3": "Option3"}, "explaination": "This is explaination."}]- Topic for questions is : ''' + query + '''- It is required that the response should be an list of objects. Don't include any other verbose explanations and don't include the markdown syntax anywhere.'''response = model.generate_content(prompt)if response.text[0] == '[':retro = json.loads(response.text)for ele in retro:ele["solved"] = Falseroadmap_collection.update_one({"_id": ObjectId(obj_id)},{"$set": { f"practice.{str(week_day)}": retro }})problems_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id}, {"_id": 1, "practice": 1})return jsonify({"success": True, "practice": problems_data['practice'] }), 200elif response.text[0] == '`':retro = json.loads(response.text[7:-3])for ele in retro:ele["solved"] = Falseroadmap_collection.update_one({"_id": ObjectId(obj_id)},{"$set": { f"practice.{str(week_day)}": retro }})problems_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id}, {"_id": 1, "practice": 1})return jsonify({"success": True, "practice": problems_data['practice'] }), 200print(response.text)return jsonify({"success": False}), 500elif data.get('type') == 2:query = data.get('query')prompt = '''Generate 5 Multiple Choice Questions with single correct answers and 4 options in the following format:[{"question": "What is that?", "options": {"1": "Option1", "2": "Option2", "3": "Option3", "4": "Option4"}, "answer" : {"3": "Option3"}, "explaination": "This is explaination."}, ... , {"question": "What is that?", "options": {"0": "Option1", "1": "Option2", "3": "Option3", "4": "Option4"}, "answer" : {"3": "Option3"}, "explaination": "This is explaination."}]- Topic for questions is : ''' + query + '''- It is required that the response should be an list of objects. Don't include any other verbose explanations and don't include the markdown syntax anywhere.'''response = model.generate_content(prompt)if response.text[0] == '[':temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})retro = json.loads(response.text)for ele in retro:ele["solved"] = Falsetemp_data['practice'][str(week_day)] += retroroadmap_collection.update_one({"_id": ObjectId(obj_id)},{"$set": { "practice": temp_data['practice'] }})problems_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id}, {"_id": 1, "practice": 1})return jsonify({"success": True, "practice": problems_data['practice'] }), 200elif response.text[0] == '`':temp_data = roadmap_collection.find_one({"_id": ObjectId(obj_id)})retro = json.loads(response.text[7:-3])for ele in retro:ele["solved"] = Falsetemp_data['practice'][str(week_day)] += retroroadmap_collection.update_one({"_id": ObjectId(obj_id)},{"$set": { "practice": temp_data['practice'] }})problems_data = roadmap_collection.find_one({"_id": ObjectId(data.get("_id")), "userId": user_id}, {"_id": 1, "practice": 1})return jsonify({"success": True, "practice": problems_data['practice'] }), 200print(response.text)return jsonify({"success": False}), 500@app.route('/problemhandler', methods=['POST'])def problemhandler():if request.method == 'POST':data = request.get_json()obj_id = data.get('_id')week_day = data.get('weekDay')indexer = data.get('index')temp = f"practice.{week_day}.{indexer}.solved"print(temp)test = roadmap_collection.update_one({"_id": ObjectId(obj_id)},{"$set": { temp : True }})print(test)return jsonify({"success": True}), 200if __name__ == '__main__':app.run(debug=True, host='0.0.0.0')
main.py+120-3