Skip to content

Commit

Permalink
Black and linted app.py, finshed up a majority of the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-Horng committed Dec 4, 2023
1 parent 4f2f4f5 commit 9da6a71
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 36 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
# Interview Review WebApp
![WebApp Machine Learning build test](https://github.com/software-students-fall2023/4-containerized-app-exercise-rizzballs/blob/main/.github/workflows/event-logger.yml/badge.svg)
![WebApp Subsystems build test](https://github.com/software-students-fall2023/4-containerized-app-exercise-rizzballs/blob/main/.github/workflows/lint.yml/badge.svg)
![WebApp Machine Learning build test](https://https://github.com/software-students-fall2023/4-containerized-app-exercise-rizzballs/blob/main/.github/workflows/event-logger.yml/badge.svg)
![WebApp Subsystems build test](https://https://github.com/software-students-fall2023/4-containerized-app-exercise-rizzballs/blob/main/.github/workflows/lint.yml/badge.svg)

## What is our WebApp?

Our WebApp is designed to help users practice and improve their interview skills. When prompted, users will speak into the microphhone and answer 3 generic interview questions. The app will record the interview and breakdown the answer given, giving a rating based on specified critera and words used. Then, it is compared to other user attempts to give a comparison and return statistics of the prompted user.
Our WebApp is designed to help users practice and improve their interview skills. When prompted, users will speak into the microphhone and answer a generic interview question. Utilizing [SpeechRecogntion](https://pypi.org/project/SpeechRecognition/), the app will record the interview and breakdown the answer given, giving a rating based on specified critera and words used. Then, it is compared to other user attempts to give a comparison and return statistics of the prompted user.

## Installation and Usage

In Progress
### Method 1: Cloning the Github Repository
1. Clone the directory through Git Bash with the command:

```
https://github.com/software-students-fall2023/4-containerized-app-exercise-rizzballs.git
```

2. Open Docker Desktop

3. In your command prompt, access the directory where you cloned the repository:
```
cd "path_to_directory"
```

4. From here, run the commands:
```
docker-compose build
docker-compose up
```

5. Now, access the http://127.0.0.1:5000/ in your browser of choice.

### Install ffmpeg (Windows)
1. Go to the official ffmpeg website, hover over the windows icon, and click Windows builds from gyan.dev
Expand Down
48 changes: 30 additions & 18 deletions machine-learning-client/machine_learning_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
client = MongoClient("mongodb://mongodb:27017/")
db = client["ml_databse"]
collection = db["transcription"]

app.config["UPLOAD_FOLDER"] = "uploads"
os.makedirs(app.config["UPLOAD_FOLDER"], exist_ok=True)
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))

pa = pyaudio.PyAudio()


def add_transcription_mongo(transcription, grade_report):
"""
Save transcription to MongoDB
Expand All @@ -41,6 +42,7 @@ def add_transcription_mongo(transcription, grade_report):
except Exception as e:
print(f"Error saving transcription to MongoDB: {e}")


def audio_to_text(audio_file_string):
"""Function for converting audio file to text transcription"""
r = sr.Recognizer()
Expand All @@ -58,11 +60,12 @@ def audio_to_text(audio_file_string):
print("success!! we transcribed it")
return transcription


def grade_transcription(transcription_text):
"""
Function to generate a page giving a break down and grade of an audio transcript someone had just recorded
"""

grade = 0
filler_words = 0
buzz_words = 0
Expand All @@ -84,7 +87,7 @@ def grade_transcription(transcription_text):
buzz_words += transcription_text.lower().count("certificate")
buzz_words += transcription_text.lower().count("qualification")
buzz_words += transcription_text.lower().count("work")
buzz_words += transcription_text.lower().count("interest")
buzz_words += transcription_text.lower().count("interest")
buzz_words += transcription_text.lower().count("develop")
buzz_words += transcription_text.lower().count("fulfill")
buzz_words += transcription_text.lower().count("refine")
Expand All @@ -96,21 +99,20 @@ def grade_transcription(transcription_text):
bz_breakdown = ""
grade_analysis = ""


if buzz_words == 0:
bz_breakdown = "You did not use any buzz words. When answering this question, try to talk about your education, work experiences, major, or any jobs you had."
elif 0 < buzz_words <= 5:
bz_breakdown = f"You used {buzz_words} buzz words. A decent answer, but you can improve. Try to find more things to say about yourself professionally."
else:
bz_breakdown = f"You used {buzz_words} buzz words. The topics of your answer are acceptable. Make sure to "
bz_breakdown = f"You used {buzz_words} buzz words. The topics of your answer are acceptable. Make sure to keep in mind your wording and topics."

if filler_words == 0:
fw_breakdown = "You did not use any filler words. Or there was a problem with the audio transcript. Either way, remember to talk confidently and at a good pace."
elif 0 < filler_words <= 5:
fw_breakdown = f"You used {filler_words} filler words. From here, you just need to practice your answer until it comes out naturally. Make sure to keep relaxed."
else:
fw_breakdown = f"You used {filler_words} filler words. When giving your answer, try speaking slower and more clearly. Don't confuse yourself by thinking too far ahead."

grade = (buzz_words * 3) - filler_words
print(grade)
if grade > 20:
Expand All @@ -127,31 +129,37 @@ def grade_transcription(transcription_text):
grade_analysis = f"Your grade is {grade}/20. You gave a very good response. Everything beyond this is fine tuning your response to the interviewer."
else:
grade_analysis = f"Your grade is {grade}/20. This should be your go to answer, but it all depends on the interviewer. This answer should could out naturally and be your basis."

grade_report = {
"filler_words": fw_breakdown,
"buzz_words": bz_breakdown,
"grade_analysis": grade_analysis
"grade_analysis": grade_analysis,
}

print(fw_breakdown)
print(bz_breakdown)
print(grade_analysis)
return grade_report


@app.route("/analyzeAudio", methods=["POST"])
def analyze_Audios():
"""
Endpoint to receive and analyze audio file
"""
try:
if "audio" not in request.files:
return jsonify({"status": "error", "message": "No audio file provided"}), 400

return (
jsonify({"status": "error", "message": "No audio file provided"}),
400,
)

audio_file = request.files["audio"]

# Delete existing files if they exist
existing_audio_path = os.path.join(app.config["UPLOAD_FOLDER"], "user_audio.wav")
existing_audio_path = os.path.join(
app.config["UPLOAD_FOLDER"], "user_audio.wav"
)
if os.path.exists(existing_audio_path):
os.remove(existing_audio_path)

Expand All @@ -174,20 +182,24 @@ def analyze_Audios():
print(true_audio_path)
# Call your functions from ml.py to process the audio
print("calling audio to text method")
transcription = audio_to_text(true_audio_path_str)
transcription = audio_to_text(true_audio_path_str)
print(transcription)
print("calling grade to text method")
print("calling grade to text method")
gradedTranscription = grade_transcription(transcription)
add_transcription_mongo(transcription, gradedTranscription)


print("we did it baby")
return jsonify({"status": "success", "message": "Audio analysis completed"}), 200

return (
jsonify({"status": "success", "message": "Audio analysis completed"}),
200,
)

except Exception as e:
return jsonify({"status": "error", "message": f"An error occurred: {str(e)}"}), 500
return (
jsonify({"status": "error", "message": f"An error occurred: {str(e)}"}),
500,
)


if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.getenv("PORT", "5001")), debug=True)

24 changes: 11 additions & 13 deletions web-app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

import os
from flask import Flask, render_template, request, jsonify
import sys
import pymongo
from pymongo import MongoClient
import requests



app = Flask("project4")


Expand All @@ -37,8 +34,9 @@ def display_results():
if not my_transcript:
return jsonify({"error": "Result not found"}), 404

return render_template("results.html", transcription_result=my_transcript, activePage="results.html")

return render_template(
"results.html", transcription_result=my_transcript, activePage="results.html"
)


@app.route("/analyzeData", methods=["POST"])
Expand All @@ -60,16 +58,16 @@ def analyze_data():
if response.status_code == 200:
result = response.json()
return jsonify(result)
else:
return (
jsonify(
{"error": "Failed to send and process audio. Please try again."}
),
500,
)
return (
jsonify(
{"error": "Failed to send and process audio. Please try again."}
),
500,
)

except FileNotFoundError as e:
return jsonify({"status": "error", "message": f"File not found: {str(e)}"})


if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.getenv("PORT", "5000")), debug=True)
app.run(host="0.0.0.0", port=int(os.getenv("PORT", "5000")), debug=True)
2 changes: 1 addition & 1 deletion web-app/templates/root.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
{% extends 'base.html' %}
{% block Base %}
<p>our application aims to help you get better at interviewing by help you practice one of th emost common interview question. To use our application press teh start recording button and begin answering the question. When you finish answering press stop recording and wait for a grade response is ready message before navigating to teh results page</p>
<p>Our application aims to help you improve your interview skills by helping you practice one of the most common interview questions. To use our application press the start recording button and begin answering the question. When you finish answering press stop recording and wait for a grade response is ready message before navigating to the results page.</p>
<h1>Question: tell me about yourself?</h3>

<div class="buttonContainer">
Expand Down

0 comments on commit 9da6a71

Please sign in to comment.