ajitesh123 / Perf-Review-AI

Write perf reviews in a minute
https://perfor-ai.streamlit.app/
2 stars 1 forks source link

ArchieAI Issue #53

Open archie-ai-code-explain-pr-review[bot] opened 2 weeks ago

archie-ai-code-explain-pr-review[bot] commented 2 weeks ago

Add the ability for users to provide audio input for their performance reviews and self-reviews. Previously, users had to type their input, but now they can record their audio. You can use streamlit audio-record (https://github.com/stefanrmmr/streamlit-audio-recorder) for this. The audio should be converted from speech to text using the Whisper model on Groq library (https://console.groq.com/docs/speech-text), and the resulting text will be used as input to the review generation process.

Main Changes:

greptile-apps[bot] commented 2 weeks ago

Implementation Steps

  1. Add streamlit audio-record to app.py:
import streamlit as st
from streamlit_audio_recorder import audio_recorder
from review import ReviewRequest, generate_review, DEFAULT_QUESTIONS
from self_review import SelfReviewRequest, generate_self_review
from llm import convert_speech_to_text

# Streamlit UI
st.set_page_config(page_title="Performance Review Assistant", layout="wide")

# Sidebar for common elements
with st.sidebar:
    st.title("Review Settings")
    review_type = st.radio("Select Review Type", ["Performance Review", "Self-Review"])
    llm_type = st.selectbox('Select LLM Type', ['openai', 'google', 'anthropic', 'groq'])
    model_size = st.selectbox('Select Model Size', ['small', 'medium', 'large'])
    user_api_key = st.text_input('Your API Key', type="password")

if review_type == "Performance Review":
    st.title("Write Performance Review in a Minute")

    st.text("""If no question is passed, the following are considered:
            1. Describe example(s) of the topics selected. What was the context? What actions did they take?
            2. In your opinion, what impact did their actions have?
            3. What recommendations do you have for their growth and development? Your feedback can be about any area of their work.
            """)

    your_role = st.text_input('Your Role')
    candidate_role = st.text_input('Candidate Role')
    perf_question = st.text_area('Performance Review Questions (one per line)', height=100)
    your_review = st.text_area('Briefly describe your experience of working with the candidate including project, responsibility of candidate, unique things they did etc., in free flow writing', height=200)
    audio_review = audio_recorder()

    if st.button('Generate Performance Review'):
        if not user_api_key:
            st.error("Please enter your API key in the sidebar.")
        elif not your_role or not candidate_role or not your_review:
            st.error("Please fill in all required fields.")
        else:
            try:
                questions = perf_question.split('\n') if perf_question else DEFAULT_QUESTIONS.split('\n')
                audio_text = convert_speech_to_text(audio_review) if audio_review else ""
                review_request = ReviewRequest(
                    your_role=your_role,
                    candidate_role=candidate_role,
                    perf_question="\n".join(questions),
                    your_review=your_review + " " + audio_text,
                    llm_type=llm_type,
                    user_api_key=user_api_key,
                    model_size=model_size
                )
                review = generate_review(**review_request.model_dump())
                for qa in review:
                    st.markdown(f"**{qa['question']}**")
                    st.markdown(qa['answer'])
                    st.markdown("---")
            except Exception as e:
                st.error(f"An error occurred: {str(e)}")
else:  # Self-Review
    st.title("Generate Your Self-Review")

    st.text("""Provide a text dump of your performance information, specific questions you want to address,
            and any additional instructions for the AI to consider while generating your self-review.""")

    text_dump = st.text_area('Text Dump (information about your performance)', height=200)
    questions = st.text_area('Questions to Answer in Self-Review (one per line)', height=100)
    instructions = st.text_area('Additional Instructions (optional)', height=100)
    audio_review = audio_recorder()

    if st.button('Generate Self-Review'):
        if not user_api_key:
            st.error("Please enter your API key in the sidebar.")
        elif not text_dump or not questions:
            st.error("Please provide both the text dump and questions.")
        else:
            try:
                question_list = [q.strip() for q in questions.split('\n') if q.strip()]
                audio_text = convert_speech_to_text(audio_review) if audio_review else ""
                self_review_request = SelfReviewRequest(
                    text_dump=text_dump + " " + audio_text,
                    questions=question_list,
                    instructions=instructions if instructions else None,
                    llm_type=llm_type,
                    user_api_key=user_api_key,
                    model_size=model_size
                )
                self_review = generate_self_review(**self_review_request.model_dump())
                for qa in self_review:
                    st.markdown(f"**{qa['question']}**")
                    st.markdown(qa['answer'])
                    st.markdown("---")
            except Exception as e:
                st.error(f"An error occurred: {str(e)}")
  1. Implement convert_speech_to_text function in llm.py:
from groq import Groq

# Add this function to llm.py

def convert_speech_to_text(audio_data):
    client = Groq(api_key=GROQ_API_KEY)
    response = client.speech_to_text(audio_data)
    return response['text']
  1. Update ReviewRequest and SelfReviewRequest models in review.py and self_review.py:
class ReviewRequest(BaseModel):
    your_role: str
    candidate_role: str
    perf_question: Optional[str] = None
    your_review: str
    audio_review: Optional[str] = None  # Add this line
    llm_type: str
    user_api_key: str
    model_size: str = "small"

class SelfReviewRequest(BaseModel):
    text_dump: str
    questions: List[str]
    instructions: Optional[str] = None
    audio_review: Optional[str] = None  # Add this line
    llm_type: str
    user_api_key: str
    model_size: str = "medium"

References

/app.py /llm.py /review.py /self_review.py

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/ajitesh123/perf-review-ai/main) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)