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

assesment.py file added for nlp task #164

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/assesment/assesment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from flask import Flask, render_template, request, jsonify
import pandas as pd
from nltk.tokenize import word_tokenize
from nltk.probability import FreqDist
import nltk
nltk.download('punkt')

app = Flask(__name__)
# @app.route('/')
# def index():
# return render_template('index.html')

@app.route('/upload', methods=['POST'])
def upload():
try:
file = request.files['file']
if file and file.filename.endswith('.csv'):
df = pd.read_csv(file)

# replace column name
text = ' '.join(df['(df[0])'])

# Basic NLP assessment
tokens = word_tokenize(text)
fdist = FreqDist(tokens)
most_common_words = fdist.most_common(10)

return jsonify(results=f"Most common words: {most_common_words}")

else:
return jsonify(error="Invalid file format. Please upload a CSV file.")
except Exception as e:
return jsonify(error = str(e))

if __name__ == '__main__':
app.run(debug=True)