Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import logging | |
| from ai_integration import get_counter_debuts | |
| from chess_api import get_user_games_from_chess_com, analyze_chess_com_user | |
| import os | |
| from core import load_eco_data | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | |
| logger = logging.getLogger(__name__) | |
| def create_interface(): | |
| with gr.Blocks(theme=gr.themes.Soft(), title="Shaxmat AI Maslahatchi", css=""" | |
| .gradio-container {font-family: 'Arial', sans-serif;} | |
| .gr-button-primary {background: linear-gradient(90deg, #667eea 0%, #764ba2 100%) !important;} | |
| h1 {text-align: center; color: #667eea;} | |
| """) as demo: | |
| gr.Markdown(""" | |
| # βοΈ SHAXMAT AI MASLAHATCHI βοΈ | |
| Professional darajadagi shaxmat tahlili va maslahatlar | |
| """) | |
| with gr.Tabs(): | |
| with gr.Tab("π― Debyut Tahlili"): | |
| gr.Markdown("### Raqibingiz debyutlariga qarshi strategiyalarni aniqlang") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| user_color = gr.Radio( | |
| choices=["Oq", "Qora"], | |
| value="Oq", | |
| label="π¨ Sizning Rangingiz", | |
| info="Qaysi rang bilan o'ynaysiz?" | |
| ) | |
| opponent_debuts = gr.Textbox( | |
| label="π Raqib Debyutlari", | |
| placeholder="Misol: e4, d4, London tizimi", | |
| lines=3, | |
| info="Raqib qanday debyutlar o'ynaydi?" | |
| ) | |
| user_repertoire = gr.Textbox( | |
| label="π Sizning Repertuaringiz (ixtiyoriy)", | |
| placeholder="Misol: e4 ga qarshi men Sicilian o'ynayman, d4 ga qarshi Grunfeld", | |
| lines=4, | |
| info="Sizning afzal ko'rgan debyutlaringiz" | |
| ) | |
| analyze_btn1 = gr.Button("β‘ Tahlil Qilish", variant="primary", size="lg") | |
| with gr.Column(scale=2): | |
| output1 = gr.Markdown(label="π Tahlil Natijasi") | |
| gr.Examples( | |
| examples=[ | |
| ["Qora", "e4, London tizimi", "e4 ga qarshi Sicilian, d4 ga qarshi Kings Indian"], | |
| ["Qora", "d4, c4", "d4 ga qarshi Grunfeld, e4 ga qarshi Karo-Kann"], | |
| ["Oq", "e4, Ispancha partiya", ""], | |
| ], | |
| inputs=[user_color, opponent_debuts, user_repertoire], | |
| label="π‘ Misollar" | |
| ) | |
| with gr.Tab("π Chess.com Tahlili"): | |
| gr.Markdown("### Raqib Chess.com profilini tahlil qiling") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| user_color2 = gr.Radio( | |
| choices=["Oq", "Qora"], | |
| value="Oq", | |
| label="π¨ Sizning Rangingiz", | |
| info="Qaysi rang bilan o'ynaysiz?" | |
| ) | |
| chess_com_username = gr.Textbox( | |
| label="π€ Chess.com Foydalanuvchi Nomi", | |
| placeholder="Misol: Hikaru", | |
| info="Raqibingiz Chess.com username" | |
| ) | |
| user_repertoire2 = gr.Textbox( | |
| label="π Sizning Repertuaringiz (ixtiyoriy)", | |
| placeholder="Misol: e4 ga qarshi Sicilian, d4 ga qarshi Kings Indian", | |
| lines=4, | |
| info="Sizning afzal ko'rgan debyutlaringiz" | |
| ) | |
| analyze_btn2 = gr.Button("π Tahlil Qilish", variant="primary", size="lg") | |
| with gr.Column(scale=2): | |
| output2 = gr.Markdown(label="π Tahlil Natijasi") | |
| gr.Examples( | |
| examples=[ | |
| ["Oq", "Hikaru", ""], | |
| ["Qora", "GothamChess", "e4 ga qarshi Sicilian"], | |
| ], | |
| inputs=[user_color2, chess_com_username, user_repertoire2], | |
| label="π‘ Misollar" | |
| ) | |
| analyze_btn1.click( | |
| fn=get_counter_debuts, | |
| inputs=[opponent_debuts, user_color, user_repertoire], | |
| outputs=output1 | |
| ) | |
| analyze_btn2.click( | |
| fn=lambda username, repertoire, color: analyze_chess_com_user(username, repertoire, color), | |
| inputs=[chess_com_username, user_repertoire2, user_color2], | |
| outputs=output2 | |
| ) | |
| return demo | |
| if __name__ == "__main__": | |
| if not os.environ.get('GOOGLE_API_KEY'): | |
| print("β οΈ GOOGLE_API_KEY muhit o'zgaruvchisini o'rnating!") | |
| print("Misol: export GOOGLE_API_KEY='sizning_kalitingiz'") | |
| else: | |
| load_eco_data() | |
| demo = create_interface() | |
| demo.launch(server_name="0.0.0.0", server_port=7860) |