import gradio as gr import cohere import os import json from dotenv import load_dotenv #from qdrant_client import QdrantClient #from qdrant_client.models import Filter, FieldCondition, MatchValue #import json load_dotenv(verbose=True) #client = QdrantClient(url="http://localhost:6333") def get_scores_for_users(userids): try: userids_list = userids.split(",") # Split user IDs into a list result_messages = [] # Store results for each userid for userid in userids_list: userid = userid.strip() # Clean up whitespace around user IDs # Build filter to query points for the specific userid filter_condition = { "must": [ { "key": "userid", "match": {"value": userid} } ] } # Query Qdrant for points matching the userid results = client.scroll( collection_name="skill_scores", limit=6, # Adjust based on your needs with_payload=True # Include payloads for manual filtering ) filtered_results = [ point.payload["score"] for point in results[0] if point.payload.get("userid") == userid ] #result_messages.append(f'{{"{userid}": {filtered_results}}}') result_messages.append(f'{{"userid":"{userid}","score": {filtered_results}}}') # Join result_messages into a single JSON-compatible string json_data = "[" + ",".join(result_messages) + "]" # Parse the JSON string into Python data parsed_data = json.loads(json_data) # Optional: Print or process parsed data print(parsed_data) # useridの取り出し userid = parsed_data[0]["userid"] print(f"User ID: {userid}") # scoreの各項目を取り出し scores = parsed_data[0]["score"] print(f"Score: {scores}") #return "\n".join(result_messages) # Return results for all user IDs return userid,scores except Exception as e: return f"Error occurred while retrieving scores: {str(e)}" def update_lang(lang): if len(lang) == 0: return gr.update(value="Pythonが得意。スクリプト作成やデータ分析、機械学習まで幅広く活用している。") else: return gr.update(value=lang) def update_debug(debug): if len(debug) == 0: return gr.update(value="よく使うのはpdb(Python Debugger)やVS Codeのデバッガ機能。エラー箇所を細かくチェックするのが好き。") else: return gr.update(value=debug) def update_recent_problem(recent_problem): if len(recent_problem) == 0: return gr.update(value="例えば、APIの連携でエラーが続発する問題があったとき、レスポンスをしっかりロギングしてパターンを分析、結果的にリクエストヘッダーを微調整して解決できた。") else: return gr.update(value=recent_problem) def update_project_approach(project_approach): if len(project_approach) == 0: return gr.update(value="チーム内でブレインストーミングしてアイデアを出し合い、最良の解決策を選択するのが常套手段だと思っている。") else: return gr.update(value=project_approach) def update_project_scale(project_scale): if len(project_scale) == 0: return gr.update(value="1人で取り組むものから、数十人規模の開発チームでクラウドシステム構築などをした経験もある。") else: return gr.update(value=project_scale) def update_team_role (team_role): if len(team_role ) == 0: return gr.update(value="主にテクニカルリーダーとして、設計からレビューまでを担当。時には新人教育も。") else: return gr.update(value=team_role) def update_learning_methods(learning_methods): if len(learning_methods) == 0: return gr.update(value="実際に手を動かして試すのが一番。Tutorialやドキュメントを読みながらプロトタイプを作成。") else: return gr.update(value=learning_methods) def update_recent_learning(recent_learning): if len(recent_learning) == 0: return gr.update(value="最近は生成AIのモデルチューニング方法について学んだよ。これでさらに便利なプロジェクトが作れる。") else: return gr.update(value=recent_learning) # スコアを抽出する関数 def post_scores(state,email): if len(email) == 0: return "検査結果がありません!" else: state['final_email'] = email state['final_comment'] = """{ "技術的な理解": 9, "問題解決能力": 8.5, "実務経験": 8, "学習意欲": 9, "ソフトスキル": 8.5, "合計スコア": 8.6 }""" co = cohere.ClientV2(api_key=os.environ.get("COHERE_API_KEY")) res = co.chat( model="command-a-03-2025", messages=[ { "role": "user", "content": f"これは{state['final_email']}さんのデータです。{state['final_comment']}を評価してください。生成された結果に基づいて{state['final_email']}さんに送るスカウト提案メールも作ってください。答えは、必ず、評価結果とメールの本文を日本語で返してください。", } ], ) data = res.message.content[0].text return data # スコアを抽出する関数 def extract_scores(state): if len(state["final_score"]) == 0: return "検査結果がありません!" else: co = cohere.ClientV2(api_key=os.environ.get("COHERE_API_KEY")) res = co.chat( model="command-a-03-2025", messages=[ { "role": "user", "content": f"これは{state['final_email']}さんのデータです。{state['final_comment']}を評価してください。生成された結果に基づいて{state['final_email']}さんに送るスカウト提案メールも作ってください。答えは、必ず、評価結果とメールの本文を日本語で返してください。", } ], ) data = res.message.content[0].text return data # 簡易評価の関数 def evaluate_responses(state, email, programming, debugging, problem, problem_solving, project_experience, role, learning, learnt_skills): state["final_email"] = email if (email != "" and programming != "" and debugging != "" and problem != "" and problem_solving != "" and project_experience != "" and role != "" and learning != "" and learnt_skills != ""): # レコード作成 records = f""" ✨プログラミング言語について: {programming} ✨デバッグ方法について: {debugging} ✨最近解決した技術的な課題: {problem} ✨プロジェクト問題解決方法について: {problem_solving} ✨プロジェクト経験について: {project_experience} ✨チームでの役割について: {role} ✨新しい技術への学習意欲について: {learning} ✨最近学んだ技術や知識について: {learnt_skills} """ co = cohere.ClientV2(api_key=os.environ.get("COHERE_API_KEY")) res = co.chat( model="command-a-03-2025", messages=[ { "role": "user", "content": f""" {records}を「基準」に基づいて各項目の合計スコアを10段階で割り振って評価してください。答えは、必ず、「形式」で合計スコアのみを返してください。 「基準」=価基準とポイント配分 技術的な理解 (30%): 例えばプログラミング言語の知識やデバッグ能力を考慮。コード品質や問題解決能力が評価対象。 問題解決能力 (25%): 技術的課題への対応スキルやアプローチ方法をチェック。現実的かつ効率的な解決策を出せるかどうか。 実務経験 (20%): 過去のプロジェクト経験の内容や規模。実際の成果や役割が評価される。 学習意欲 (15%): 新しい技術をどれだけ積極的に学び、適応しているか。最近学んだ知識がアピールポイント! ソフトスキル (10%): チームワークやコミュニケーション能力。エンジニアの柔軟性や協力姿勢を評価。 「形式」= {{ "技術的な理解": 9, "問題解決能力": 8.5, "実務経験": 8, "学習意欲": 9.5, "ソフトスキル": 8.5, "合計スコア": 8.63, "スキルレベル": "Expert", "説明": "技術力や問題解決能力、学習意欲が高くバランスの良いスキルセットを持っている。" }} """, } ], ) cleaned_string = res.message.content[0].text.replace("```json", "").replace("```", "").strip() data = json.loads(cleaned_string) #data = json.loads(res.message.content[0].text) comments = "\n".join([f"{key}: {value}" for key, value in data.items()]) scores = [f"{key}: {value}" for key, value in data.items()] print("db-scores:",scores) state["final_comment"] = comments state["final_score"] = scores return records, comments else: return "入力が正しくありません。","None" # Gradio Blocksの構築 with gr.Blocks(css="footer {visibility: hidden;} #header {display: flex; justify-content: space-between; align-items: center; font-size: 24px; font-weight: bold;} #logo {width: 50px; height: 50px;}", theme=gr.themes.Glass(), title="エンジニア・スキル評価") as inquery: state = gr.State({ "final_email": "", "final_comment": "", "final_score": [], }) gr.HTML('
