ajitesh123 / auto-review-ai

๐Ÿš€ AI-Powered Performance Review Generator
https://perfor-ai.streamlit.app/
3 stars 1 forks source link

Add Audio Input for Performance Reviews #96

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

archie-ai-code-explain-pr-review[bot] commented 4 months ago
greptile-apps[bot] commented 4 months ago

Implementation Steps

  1. Install streamlit-audio-recorder:

    pip install streamlit-audio-recorder
  2. 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[bytes] = 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[bytes] = None  # Add this line
       llm_type: str
       user_api_key: str
       model_size: str = "medium"
  3. Implement convert_speech_to_text Function:

    # In llm.py
    from groq import Whisper
    
    def convert_speech_to_text(audio_data: bytes) -> str:
       whisper = Whisper(api_key=GROQ_API_KEY)
       return whisper.transcribe(audio_data)
  4. Update app.py for Audio Input:

    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
    
    # Add audio recorder to the UI
    audio_data = audio_recorder()
    
    if review_type == "Performance Review":
       # Existing code...
       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_data) if audio_data else None
                   review_request = ReviewRequest(
                       your_role=your_role,
                       candidate_role=candidate_role,
                       perf_question="\n".join(questions),
                       your_review=your_review,
                       audio_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
       # Existing code...
       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_data) if audio_data else None
                   self_review_request = SelfReviewRequest(
                       text_dump=text_dump,
                       questions=question_list,
                       instructions=instructions if instructions else None,
                       audio_review=audio_text,
                       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)}")

    }

References

/app.py /review.py /self_review.py /llm.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)