File size: 5,380 Bytes
80e55f8
613bf74
bdd9340
80e55f8
 
 
 
 
bdd9340
 
 
832c6b9
613bf74
d10024d
 
 
 
 
 
613bf74
d10024d
613bf74
d10024d
613bf74
 
d10024d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11c35f2
d10024d
 
 
 
 
 
 
 
 
 
 
bdd9340
 
 
d10024d
1849320
d10024d
613bf74
bdd9340
80e55f8
 
 
 
 
 
 
 
 
 
 
bdd9340
80e55f8
 
 
 
 
 
 
 
 
 
 
 
 
 
bdd9340
80e55f8
 
 
 
 
 
 
 
 
 
 
 
d10024d
 
1849320
d10024d
613bf74
bdd9340
 
80e55f8
 
bdd9340
 
1849320
613bf74
 
 
685a245
 
 
 
bdd9340
613bf74
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

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)