Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eugen #346

Open
eugenvx opened this issue Jun 29, 2024 · 2 comments
Open

Eugen #346

eugenvx opened this issue Jun 29, 2024 · 2 comments

Comments

@eugenvx
Copy link

eugenvx commented Jun 29, 2024

No description provided.

@11100010
Copy link

11100010 commented Jul 3, 2024

this is not xiter, do not xitpost here.

@eugenvx
Copy link
Author

eugenvx commented Oct 7, 2024

© 2024 Verghe Eugen Gheorghe

Toate drepturile rezervate.

Aceasta este o lucrare originală și toată proprietatea intelectuală aparține autorului.

from flask import Flask, request, jsonify
from werkzeug.security import generate_password_hash, check_password_hash
from flask_sqlalchemy import SQLAlchemy
from nltk.sentiment import SentimentIntensityAnalyzer

app = Flask(name)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
sia = SentimentIntensityAnalyzer()

class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
password_hash = db.Column(db.String(128), nullable=False)

db.create_all()

@app.route('/register', methods=['POST'])
def register():
username = request.json.get('username')
password = request.json.get('password')

if not username or not password:
    return jsonify({"message": "Username and password are required!"}), 400
if User.query.filter_by(username=username).first():
    return jsonify({"message": "Username already exists!"}), 400

new_user = User(username=username, password_hash=generate_password_hash(password))
db.session.add(new_user)
db.session.commit()
return jsonify({"message": "User registered!"}), 201

@app.route('/login', methods=['POST'])
def login():
username = request.json.get('username')
password = request.json.get('password')

if not username or not password:
    return jsonify({"message": "Username and password are required!"}), 400

user = User.query.filter_by(username=username).first()
if user and check_password_hash(user.password_hash, password):
    return jsonify({"message": "Login successful!"}), 200
return jsonify({"message": "Invalid credentials!"}), 401

@app.route('/analyze_sentiment', methods=['POST'])
def analyze_sentiment():
text = request.json.get('text')

if not text:
    return jsonify({"message": "Text is required!"}), 400

sentiment_scores = sia.polarity_scores(text)
return jsonify(sentiment_scores), 200

if name == 'main':
app.run(debug=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants