Spaces:
Runtime error
Runtime error
| import pandas as pd | |
| import google.generativeai as genai | |
| import os | |
| # Load responses from a file | |
| def load_responses(filename="interview_responses_round_1.csv"): | |
| try: | |
| return pd.read_csv(filename) | |
| except FileNotFoundError: | |
| print("Response file not found. Please ensure that 'round1.py' has been run and responses have been saved.") | |
| exit() | |
| # Configure and initialize Gemini | |
| def configure_gemini(): | |
| api_key = os.getenv("GOOGLE_GENERATIVE_AI_API_KEY") | |
| if not api_key: | |
| print("Google Generative AI API key not set. Please set your API key as an environment variable.") | |
| exit() | |
| genai.configure(api_key=api_key) | |
| generation_config = { | |
| "temperature": 0.9, | |
| "top_p": 1, | |
| "top_k": 50, | |
| "max_output_tokens": 512, | |
| } | |
| safety_settings = [ | |
| {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| ] | |
| return genai.GenerativeModel(model_name="gemini-1.0-pro", | |
| generation_config=generation_config, | |
| safety_settings=safety_settings) | |
| def evaluate_responses(model, responses): | |
| evaluations = [] | |
| for index, row in responses.iterrows(): | |
| try: | |
| response = model.generate_content([row['response']]) | |
| evaluations.append(response.text) | |
| except Exception as e: | |
| print(f"An error occurred while evaluating response {index+1}: {e}") | |
| evaluations.append("Error during evaluation.") | |
| return evaluations | |
| def print_evaluations(responses, evaluations): | |
| for index, (response, evaluation) in enumerate(zip(responses['response'], evaluations), start=1): | |
| print(f"Response {index}: {response}") | |
| print(f"Evaluation: {evaluation}") | |
| print("----------") | |
| if __name__ == "__main__": | |
| responses = load_responses() | |
| if not responses.empty: | |
| model = configure_gemini() | |
| evaluations = evaluate_responses(model, responses) | |
| print_evaluations(responses, evaluations) | |