Spaces:
Sleeping
Sleeping
| import datetime | |
| import google.generativeai as genai | |
| import os | |
| genai.configure(api_key=os.environ.get('GOOGLE_API_KEY')) | |
| model = genai.GenerativeModel('gemini-2.5-flash') | |
| def get_counter_debuts(opponent_debuts, user_color, user_repertoire): | |
| if not opponent_debuts or not opponent_debuts.strip(): | |
| return "β Iltimos, kamida bitta debyt kiriting!" | |
| color_context = "Siz oq rangli o'ynaysiz." if user_color == "Oq" else "Siz qora rangli o'ynaysiz." | |
| repertoire_context = "" | |
| if user_repertoire and user_repertoire.strip(): | |
| repertoire_context = f"\n\nFOYDALANUVCHI REPERTUARI:\n{user_repertoire}\n\nIltimos, bu repertuarni hisobga olib tavsiyalar bering." | |
| prompt = f""" | |
| Siz professional shaxmat murabbiyisiz. {color_context} | |
| Raqib quyidagi debyutlarni o'ynaydi: | |
| {opponent_debuts} | |
| {repertoire_context} | |
| Har bir raqib debyuti uchun quyidagilarni bering: | |
| ## DEBYT NOMI | |
| **Qarshi Debyt:** [Eng yaxshi qarshi debyt] | |
| **Asosiy G'oya:** | |
| [2-3 jumlada tushuntirish] | |
| **Strategik Rejalar:** | |
| - [Reja 1] | |
| - [Reja 2] | |
| - [Reja 3] | |
| **Muhim Yurishlar:** | |
| [Boshlanish yurishlari ketma-ketligi] | |
| **Tuzoqlar va Ehtiyot Choralari:** | |
| [Diqqat qilish kerak bo'lgan narsalar] | |
| --- | |
| Javobni o'zbek tilida, toza markdown formatida bering. | |
| """ | |
| try: | |
| response = model.generate_content(prompt) | |
| fixed_response = response.text.strip() | |
| result = f"""# π SHAXMAT TAHLILI NATIJALARI | |
| **Sana:** {datetime.now().strftime("%Y-%m-%d %H:%M")} | |
| **Sizning Rangingiz:** {user_color} | |
| --- | |
| {fixed_response} | |
| --- | |
| ## π‘ QO'SHIMCHA MASLAHATLAR | |
| 1. **O'rganish:** Har bir debyutni lichess.org/learn yoki chess.com da mashq qiling | |
| 2. **Tahlil:** O'yinlaringizni tahlil qiling va xatolarni toping | |
| 3. **Mashq:** Turli holatlarni mashq qiling | |
| 4. **Vaqt:** Har bir debyutga kamida 30 daqiqa ajrating | |
| β **Omad tilaymiz! Yaxshi o'ynang!** βοΈ | |
| """ | |
| return result | |
| except Exception as e: | |
| return f"β Xatolik yuz berdi: {str(e)}\n\nIltimos, GOOGLE_API_KEY to'g'ri o'rnatilganligini tekshiring." | |