Spaces:
Runtime error
Runtime error
Sync from GitHub via hub-sync
Browse files37 unmodified lines383940414243444546474849505152532 unmodified lines56575859606137 unmodified linestry:request_data = request.model_dump()prediction_result = ml_model.predict(request_data["text"])log_entry = InferenceLog(input_text=request_data['text'],sentiment_prediction=prediction_result['sentiment'],confidence_score=prediction_result['confidence'],timestamp=datetime.now(timezone.utc))db.add(log_entry)db.commit()db.close()return SentimentResponse(input_text=request_data["text"],2 unmodified linestimestamp=log_entry.timestamp)except Exception as e:raise HTTPException(status_code=500, detail=str(e))37 unmodified lines38394041424344454647484950515253542 unmodified lines5758596061626337 unmodified linestry:request_data = request.model_dump()prediction_result = ml_model.predict(request_data["text"])current_time = datetime.now(timezone.utc)log_entry = InferenceLog(input_text=request_data['text'],sentiment_prediction=prediction_result['sentiment'],confidence_score=prediction_result['confidence'],timestamp=current_time)db.add(log_entry)db.commit()db.refresh(log_entry) # Refresh to get the generated ID and timestamp from the databasereturn SentimentResponse(input_text=request_data["text"],2 unmodified linestimestamp=log_entry.timestamp)except Exception as e:db.rollback() # Rollback in case of any error during database operationsraise HTTPException(status_code=500, detail=str(e))
app/main.py+4-2