ajitesh123 / auto-review-ai

🚀 AI-Powered Performance Review Generator
https://www.tryarchieai.com/
3 stars 1 forks source link

Add Audio Input for Performance Reviews #95

Open archie-ai-code-explain-pr-review[bot] opened 4 months ago

archie-ai-code-explain-pr-review[bot] commented 4 months ago
dev-archie-ai-code-explain-pr[bot] commented 3 months ago

🔍 Processing Issue [=== ] 𝙋𝙧𝙤𝙘𝙚𝙨𝙨𝙞𝙣𝙜...

Steps: [ ] Problem discovery: Understand the issue and find related files/code [ ] Determine approach: Decide higher level plan approach [ ] Implementation plan: Create a detailed plan of action [ ] Code generation: Write the code to solve the issue

This issue will be updated as we make progress.

dev-archie-ai-code-explain-pr[bot] commented 3 months ago

Processed and cleaned issue:

Feature Request: Add Audio Input for Performance Reviews

Main Objective:

Technical Requirements:

  1. Audio Recording:

    • Use the streamlit-audio-recorder library to implement audio recording in the app.
  2. Speech-to-Text Conversion:

    • Implement the convert_speech_to_text function.
    • Utilize the Whisper model on the Groq library for audio-to-text conversion.
  3. Data Model Updates:

    • Update ReviewRequest model to include an optional audio_review field.
    • Update SelfReviewRequest model to include an optional audio_review field.
  4. Application Logic Updates:

    • Modify the review generation logic in app.py to handle the new audio_review field.
    • Use the audio input for generating both reviews and self-reviews.

Implementation Steps:

  1. Integrate streamlit-audio-recorder for audio capture.
  2. Develop convert_speech_to_text function using Whisper model and Groq library.
  3. Update data models (ReviewRequest and SelfReviewRequest) with audio_review field.
  4. Modify app.py to process audio input and generate reviews accordingly.

Note: Ensure that the existing text-based input functionality is maintained alongside the new audio input feature.

dev-archie-ai-code-explain-pr[bot] commented 3 months ago

Scope Analysis for Requested Changes

Summary

Detailed Breakdown

Files to Modify

These existing files need to be updated:

Files to Create

These new files need to be created:

Reference Files

These files are important for context but don't need direct modification:

The implementation plan will be based on these files.

dev-archie-ai-code-explain-pr[bot] commented 3 months ago

🎯 Task Breakdown

To address this issue effectively, I've broken it down into the following subtasks:

I'll work through these subtasks systematically to resolve the issue.

dev-archie-ai-code-explain-pr[bot] commented 3 months ago

Design Proposal

🔍 Root Cause Analysis

The root cause of this issue is the lack of audio input functionality in the current performance review system. The existing system only supports text-based input for reviews and self-reviews. To address this, we need to implement audio recording, speech-to-text conversion, and integrate these new features into the existing application logic. The most critical components to resolve this issue are:

  1. Adding the necessary library (streamlit-audio-recorder) for audio capture.
  2. Implementing speech-to-text conversion using the Whisper model and Groq library.
  3. Updating the data models to include an audio_review field.
  4. Modifying the application logic to process audio input and generate reviews accordingly.

By addressing these components, we can successfully add the requested audio input feature while maintaining the existing text-based functionality.

💡 Proposed Changes

1: 1. Update requirements.txt to include streamlit-audio-recorder

  1. Open the requirements.txt file
  2. Add the streamlit-audio-recorder library to the file
    • Locate the end of the file
    • Add a new line with "streamlit-audio-recorder==0.0.3" (or the latest version available)

Example:

  1. Open the file at /requirements.txt
  2. Add the following line at the end of the file: streamlit-audio-recorder==0.0.3

2: 2. Create a new file for speech-to-text conversion

  1. Create a new file named speech_to_text.py in the src directory
  2. Import necessary libraries
    • Add import statements for groq and whisper
  3. Implement the convert_speech_to_text function
    • Define the function that takes an audio file as input
    • Use the Whisper model from the Groq library to convert speech to text
    • Return the transcribed text

Example:

  1. Create a new file at /src/speech_to_text.py
  2. Add the following content to the file:
import groq
import whisper

def convert_speech_to_text(audio_file):
    # Initialize the Whisper model
    model = whisper.load_model("base")

    # Transcribe the audio
    result = model.transcribe(audio_file)

    # Return the transcribed text
    return result["text"]

3: 3. Update review.py to include audio_review field

  1. Open the review.py file in the src directory
  2. Locate the ReviewRequest class
  3. Add the audio_review field to the class
    • Add a new field named audio_review of type str with an Optional wrapper
  4. Update the class docstring to include information about the new field

Example:

  1. Open the file at /src/review.py
  2. Locate the ReviewRequest class
  3. Add the following field to the class: audio_review: Optional[str] = None
  4. Update the class docstring to include: :param audio_review: Optional audio review input

4: 4. Update self_review.py to include audio_review field

  1. Open the self_review.py file in the src directory
  2. Locate the SelfReviewRequest class
  3. Add the audio_review field to the class
    • Add a new field named audio_review of type str with an Optional wrapper
  4. Update the class docstring to include information about the new field

Example:

  1. Open the file at /src/self_review.py
  2. Locate the SelfReviewRequest class
  3. Add the following field to the class: audio_review: Optional[str] = None
  4. Update the class docstring to include: :param audio_review: Optional audio review input

5: 5. Modify app.py to integrate audio recording and processing

  1. Open the app.py file in the src directory
  2. Import necessary modules
    • Add import statement for streamlit_audio_recorder
    • Add import statement for the convert_speech_to_text function from speech_to_text module
  3. Add audio recording functionality
    • Create a new section for audio input using st.expander
    • Use streamlit_audio_recorder to capture audio input
  4. Implement speech-to-text conversion
    • Check if audio input is provided
    • If audio input exists, call convert_speech_to_text function
  5. Update review generation logic
    • Modify the existing logic to use audio input if available
    • Combine text and audio inputs if both are provided

Example:

  1. Open the file at /src/app.py
  2. Add the following import statements at the beginning of the file: from streamlit_audio_recorder import st_audiorec from speech_to_text import convert_speech_to_text
  3. Add the following code for audio recording (place it appropriately within the existing UI structure):
    with st.expander("Audio Input"):
       audio_bytes = st_audiorec()
       if audio_bytes:
           st.audio(audio_bytes, format="audio/wav")
  4. Implement speech-to-text conversion:
    audio_text = None
    if audio_bytes:
       audio_text = convert_speech_to_text(audio_bytes)
       st.write("Transcribed text:", audio_text)
  5. Update the review generation logic:

    # Combine text and audio inputs
    combined_input = ""
    if st.session_state.messages[-1]["content"]:
       combined_input += st.session_state.messages[-1]["content"]
    if audio_text:
       combined_input += " " + audio_text
    
    # Use combined_input for generating reviews
    # Update the existing logic to use combined_input instead of just text input

6: 6. Create test cases for new functionality

  1. Create a new file named test_audio_features.py in the tests directory
  2. Import necessary modules and functions
  3. Implement test cases for speech-to-text conversion
  4. Implement test cases for audio input in ReviewRequest and SelfReviewRequest
  5. Implement test cases for audio processing in app.py

Example:

  1. Create a new file at /tests/test_audio_features.py
  2. Add the following content to the file:
import unittest
from src.speech_to_text import convert_speech_to_text
from src.review import ReviewRequest
from src.self_review import SelfReviewRequest
from src.app import process_audio_input  # Assuming this function exists in app.py

class TestAudioFeatures(unittest.TestCase):
    def test_speech_to_text_conversion(self):
        # Test the convert_speech_to_text function
        audio_file = "path/to/test/audio/file.wav"
        result = convert_speech_to_text(audio_file)
        self.assertIsInstance(result, str)
        self.assertGreater(len(result), 0)

    def test_review_request_with_audio(self):
        # Test ReviewRequest with audio_review field
        review = ReviewRequest(employee_name="John Doe", audio_review="Test audio review")
        self.assertEqual(review.audio_review, "Test audio review")

    def test_self_review_request_with_audio(self):
        # Test SelfReviewRequest with audio_review field
        self_review = SelfReviewRequest(employee_name="Jane Doe", audio_review="Test audio self-review")
        self.assertEqual(self_review.audio_review, "Test audio self-review")

    def test_app_audio_processing(self):
        # Test audio processing in app.py
        audio_input = b"dummy audio data"
        result = process_audio_input(audio_input)
        self.assertIsNotNone(result)

if __name__ == '__main__':
    unittest.main()
dev-archie-ai-code-explain-pr[bot] commented 3 months ago

Implementation Plan

Step 1: ## File: /requirements.txt

File: /requirements.txt

Describe ALL changes to be made: Add the streamlit-audio-recorder library to the requirements.txt file.

Original Code:

# Existing requirements
streamlit==1.10.0
openai==0.27.0
python-dotenv==0.19.2

New Code:

# Existing requirements
streamlit==1.10.0
openai==0.27.0
python-dotenv==0.19.2
streamlit-audio-recorder==0.0.3

Step 2: ## File: /src/speech_to_text.py

File: /src/speech_to_text.py

Describe ALL changes to be made: Create a new file speech_to_text.py in the src directory. Implement the convert_speech_to_text function using the Whisper model from the Groq library.

New Code:

import groq
import whisper

def convert_speech_to_text(audio_file):
    # Initialize the Whisper model
    model = whisper.load_model("base")

    # Transcribe the audio
    result = model.transcribe(audio_file)

    # Return the transcribed text
    return result["text"]

Step 3: ## File: /src/review.py

File: /src/review.py

Describe ALL changes to be made: Update the ReviewRequest class to include the audio_review field and update the class docstring.

Original Code:

from typing import Optional

class ReviewRequest:
    """
    Represents a request for a performance review.

    :param employee_name: Name of the employee being reviewed
    :param review_period: Period for which the review is being conducted
    :param achievements: Notable achievements during the review period
    :param areas_for_improvement: Areas where the employee can improve
    :param goals: Goals for the next review period
    """

    def __init__(
        self,
        employee_name: str,
        review_period: str,
        achievements: Optional[str] = None,
        areas_for_improvement: Optional[str] = None,
        goals: Optional[str] = None
    ):
        self.employee_name = employee_name
        self.review_period = review_period
        self.achievements = achievements
        self.areas_for_improvement = areas_for_improvement
        self.goals = goals

New Code:

from typing import Optional

class ReviewRequest:
    """
    Represents a request for a performance review.

    :param employee_name: Name of the employee being reviewed
    :param review_period: Period for which the review is being conducted
    :param achievements: Notable achievements during the review period
    :param areas_for_improvement: Areas where the employee can improve
    :param goals: Goals for the next review period
    :param audio_review: Optional audio review input
    """

    def __init__(
        self,
        employee_name: str,
        review_period: str,
        achievements: Optional[str] = None,
        areas_for_improvement: Optional[str] = None,
        goals: Optional[str] = None,
        audio_review: Optional[str] = None
    ):
        self.employee_name = employee_name
        self.review_period = review_period
        self.achievements = achievements
        self.areas_for_improvement = areas_for_improvement
        self.goals = goals
        self.audio_review = audio_review

Step 4: ## File: /src/self_review.py

File: /src/self_review.py

Describe ALL changes to be made: Update the SelfReviewRequest class to include the audio_review field and update the class docstring.

Original Code:

from typing import Optional

class SelfReviewRequest:
    """
    Represents a request for a self-review.

    :param employee_name: Name of the employee conducting the self-review
    :param review_period: Period for which the self-review is being conducted
    :param achievements: Notable achievements during the review period
    :param challenges: Challenges faced during the review period
    :param goals: Goals for the next review period
    """

    def __init__(
        self,
        employee_name: str,
        review_period: str,
        achievements: Optional[str] = None,
        challenges: Optional[str] = None,
        goals: Optional[str] = None
    ):
        self.employee_name = employee_name
        self.review_period = review_period
        self.achievements = achievements
        self.challenges = challenges
        self.goals = goals

New Code:

from typing import Optional

class SelfReviewRequest:
    """
    Represents a request for a self-review.

    :param employee_name: Name of the employee conducting the self-review
    :param review_period: Period for which the self-review is being conducted
    :param achievements: Notable achievements during the review period
    :param challenges: Challenges faced during the review period
    :param goals: Goals for the next review period
    :param audio_review: Optional audio review input
    """

    def __init__(
        self,
        employee_name: str,
        review_period: str,
        achievements: Optional[str] = None,
        challenges: Optional[str] = None,
        goals: Optional[str] = None,
        audio_review: Optional[str] = None
    ):
        self.employee_name = employee_name
        self.review_period = review_period
        self.achievements = achievements
        self.challenges = challenges
        self.goals = goals
        self.audio_review = audio_review

Step 5: ## File: /src/app.py

File: /src/app.py

Describe ALL changes to be made: Import necessary modules for audio recording and speech-to-text conversion.

Original Code:

import streamlit as st
from review import ReviewRequest
from self_review import SelfReviewRequest
# Other existing imports

New Code:

import streamlit as st
from review import ReviewRequest
from self_review import SelfReviewRequest
from streamlit_audio_recorder import st_audiorec
from speech_to_text import convert_speech_to_text
# Other existing imports

Step 6: ## File: /src/app.py

File: /src/app.py

Describe ALL changes to be made: Add audio recording functionality and implement speech-to-text conversion.

Original Code:

def main():
    st.title("Performance Review Generator")

    review_type = st.radio("Select review type:", ("Performance Review", "Self-Review"))

    if review_type == "Performance Review":
        employee_name = st.text_input("Employee Name")
        review_period = st.text_input("Review Period")
        achievements = st.text_area("Achievements")
        areas_for_improvement = st.text_area("Areas for Improvement")
        goals = st.text_area("Goals for Next Period")

        if st.button("Generate Review"):
            review_request = ReviewRequest(
                employee_name=employee_name,
                review_period=review_period,
                achievements=achievements,
                areas_for_improvement=areas_for_improvement,
                goals=goals
            )
            # Generate and display review

    elif review_type == "Self-Review":
        employee_name = st.text_input("Employee Name")
        review_period = st.text_input("Review Period")
        achievements = st.text_area("Achievements")
        challenges = st.text_area("Challenges")
        goals = st.text_area("Goals for Next Period")

        if st.button("Generate Self-Review"):
            self_review_request = SelfReviewRequest(
                employee_name=employee_name,
                review_period=review_period,
                achievements=achievements,
                challenges=challenges,
                goals=goals
            )
            # Generate and display self-review

if __name__ == "__main__":
    main()

New Code:

def main():
    st.title("Performance Review Generator")

    review_type = st.radio("Select review type:", ("Performance Review", "Self-Review"))

    if review_type == "Performance Review":
        employee_name = st.text_input("Employee Name")
        review_period = st.text_input("Review Period")
        achievements = st.text_area("Achievements")
        areas_for_improvement = st.text_area("Areas for Improvement")
        goals = st.text_area("Goals for Next Period")

        with st.expander("Audio Input"):
            audio_bytes = st_audiorec()
            if audio_bytes:
                st.audio(audio_bytes, format="audio/wav")

        if st.button("Generate Review"):
            audio_text = None
            if audio_bytes:
                audio_text = convert_speech_to_text(audio_bytes)
                st.write("Transcribed text:", audio_text)

            combined_input = ""
            if achievements:
                combined_input += f"Achievements: {achievements}\n"
            if areas_for_improvement:
                combined_input += f"Areas for Improvement: {areas_for_improvement}\n"
            if goals:
                combined_input += f"Goals: {goals}\n"
            if audio_text:
                combined_input += f"Audio Input: {audio_text}\n"

            review_request = ReviewRequest(
                employee_name=employee_name,
                review_period=review_period,
                achievements=achievements,
                areas_for_improvement=areas_for_improvement,
                goals=goals,
                audio_review=audio_text
            )
            # Generate and display review using combined_input

    elif review_type == "Self-Review":
        employee_name = st.text_input("Employee Name")
        review_period = st.text_input("Review Period")
        achievements = st.text_area("Achievements")
        challenges = st.text_area("Challenges")
        goals = st.text_area("Goals for Next Period")

        with st.expander("Audio Input"):
            audio_bytes = st_audiorec()
            if audio_bytes:
                st.audio(audio_bytes, format="audio/wav")

        if st.button("Generate Self-Review"):
            audio_text = None
            if audio_bytes:
                audio_text = convert_speech_to_text(audio_bytes)
                st.write("Transcribed text:", audio_text)

            combined_input = ""
            if achievements:
                combined_input += f"Achievements: {achievements}\n"
            if challenges:
                combined_input += f"Challenges: {challenges}\n"
            if goals:
                combined_input += f"Goals: {goals}\n"
            if audio_text:
                combined_input += f"Audio Input: {audio_text}\n"

            self_review_request = SelfReviewRequest(
                employee_name=employee_name,
                review_period=review_period,
                achievements=achievements,
                challenges=challenges,
                goals=goals,
                audio_review=audio_text
            )
            # Generate and display self-review using combined_input

if __name__ == "__main__":
    main()

Step 7: ## File: /tests/test_audio_features.py

File: /tests/test_audio_features.py

Describe ALL changes to be made: Create a new file test_audio_features.py in the tests directory and implement test cases for the new audio functionality.

New Code:

import unittest
from unittest.mock import patch, MagicMock
from src.speech_to_text import convert_speech_to_text
from src.review import ReviewRequest
from src.self_review import SelfReviewRequest

class TestAudioFeatures(unittest.TestCase):
    @patch('whisper.load_model')
    def test_speech_to_text_conversion(self, mock_load_model):
        mock_model = MagicMock()
        mock_model.transcribe.return_value = {"text": "Test transcription"}
        mock_load_model.return_value = mock_model

        audio_file = b"dummy audio data"
        result = convert_speech_to_text(audio_file)

        self.assertEqual(result, "Test transcription")
        mock_load_model.assert_called_once_with("base")
        mock_model.transcribe.assert_called_once_with(audio_file)

    def test_review_request_with_audio(self):
        review = ReviewRequest(
            employee_name="John Doe",
            review_period="2023",
            audio_review="Test audio review"
        )
        self.assertEqual(review.audio_review, "Test audio review")

    def test_self_review_request_with_audio(self):
        self_review = SelfReviewRequest(
            employee_name="Jane Doe",
            review_period="2023",
            audio_review="Test audio self-review"
        )
        self.assertEqual(self_review.audio_review, "Test audio self-review")

if __name__ == '__main__':
    unittest.main()

dev-archie-ai-code-explain-pr[bot] commented 3 months ago

Failed generated runnbale code

Justification:

Code changes doesn't address the issue: The proposed changes do not effectively resolve the git issue for the following reasons:

  1. No actual code changes have been implemented or provided for review.
  2. The streamlit-audio-recorder library, which is crucial for the audio recording functionality, is not included in the requirements.txt file.
  3. There are no visible updates to the data models (ReviewRequest and SelfReviewRequest) to include the audio_review field.
  4. The convert_speech_to_text function implementation is not present.
  5. No modifications to app.py for handling audio input are evident.

To resolve this issue, the following minimal changes are needed:

  1. Add streamlit-audio-recorder to the requirements.txt file.
  2. Implement the audio recording feature using streamlit-audio-recorder.
  3. Create the convert_speech_to_text function using the Whisper model via Groq.
  4. Update the data models to include the audio_review field.
  5. Modify app.py to handle audio input and generate reviews accordingly.

Once these changes are implemented and visible for review, a more accurate assessment of the issue resolution can be made.

Please use the code suggestion above to manually apply.

dosubot[bot] commented 4 days ago

Hi, @archie-ai-code-explain-pr-review. I'm Dosu, and I'm helping the auto-review-ai team manage their backlog. I'm marking this issue as stale.

Issue Summary:

Next Steps:

Thank you for your understanding and contribution!