Open archie-ai-code-explain-pr-review[bot] opened 1 month ago
Install streamlit-audio-recorder
:
pip install streamlit-audio-recorder
Update ReviewRequest
and SelfReviewRequest
Models:
review.py
and self_review.py
, add an optional audio_review
field:
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"
Implement convert_speech_to_text
Function:
llm.py
, add the following function:
def convert_speech_to_text(audio_data: bytes) -> str:
from groq import Whisper
whisper = Whisper(api_key=GROQ_API_KEY)
return whisper.transcribe(audio_data)
Update app.py
for Audio Input:
from streamlit_audio_recorder import audio_recorder
from llm import convert_speech_to_text
audio_review = audio_recorder()
if audio_review:
audio_text = convert_speech_to_text(audio_review)
audio_text
if available:
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 or audio_text):
st.error("Please fill in all required fields.")
else:
try:
questions = perf_question.split('\n') if perf_question else DEFAULT_QUESTIONS.split('\n')
review_request = ReviewRequest(
your_role=your_role,
candidate_role=candidate_role,
perf_question="\n".join(questions),
your_review=your_review or audio_text,
audio_review=audio_review,
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)}")
/app.py /review.py /self_review.py /llm.py
streamlit-audio-recorder
library to allow audio recording in the app.convert_speech_to_text
function using the Whisper model on the Groq library to convert the audio to text.ReviewRequest
andSelfReviewRequest
models to include an optionalaudio_review
field, and use this input for generating the review and self-review.app.py
to handle the newaudio_review
field.