Closed archie-ai-code-explain-pr-review[bot] closed 1 month ago
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"
# In app.py
from streamlit_audio_recorder import audio_recorder
# Inside the Performance Review section
st.title("Write Performance Review in a Minute")
audio_review = audio_recorder()
# Inside the Self-Review section
st.title("Generate Your Self-Review")
audio_review = audio_recorder()
convert_speech_to_text
Function:# In llm.py
from groq import Whisper
def convert_speech_to_text(audio_data: str, api_key: str) -> str:
whisper = Whisper(api_key=api_key)
text = whisper.transcribe(audio_data)
return text
# In app.py
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:
if audio_review:
your_review = convert_speech_to_text(audio_review, user_api_key)
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,
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)}")
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:
if audio_review:
text_dump = convert_speech_to_text(audio_review, user_api_key)
question_list = [q.strip() for q in questions.split('\n') if q.strip()]
self_review_request = SelfReviewRequest(
text_dump=text_dump,
questions=question_list,
instructions=instructions if instructions else None,
audio_review=audio_review,
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)}")
/app.py /self_review.py /review.py /llm.py
streamlit-audio-recorder
library to enable audio recording in the appconvert_speech_to_text
function using the Whisper model on the Groq library to convert the audio to textReviewRequest
andSelfReviewRequest
models to include an optionalaudio_review
field, and use this input for generating the review and self-review