File size: 5,644 Bytes
6ae645e
9b00313
62058a4
83c0537
6ae645e
2924e8e
83c0537
e3382c2
 
 
62058a4
88900ab
 
 
 
b4b3712
83c0537
 
4004f41
88900ab
 
83c0537
88900ab
 
b4a4d6e
83c0537
4004f41
587110e
83c0537
b4a4d6e
88900ab
b4a4d6e
83c0537
88900ab
2924e8e
 
b4a4d6e
83c0537
587110e
b4a4d6e
 
62058a4
88900ab
62058a4
88900ab
62058a4
88900ab
 
 
b4a4d6e
62058a4
88900ab
 
 
62058a4
88900ab
 
 
 
 
587110e
b4a4d6e
62058a4
587110e
83c0537
62058a4
83c0537
88900ab
 
 
 
b4a4d6e
62058a4
88900ab
2924e8e
88900ab
 
 
2924e8e
62058a4
 
88900ab
62058a4
88900ab
b4a4d6e
5a2307a
 
 
 
 
88900ab
 
 
 
 
 
 
 
 
587110e
88900ab
3f25aef
 
 
88900ab
 
 
 
 
 
 
 
 
 
 
 
b4a4d6e
 
8ea6312
62058a4
8ea6312
62058a4
8ea6312
 
 
 
 
 
 
 
 
 
62058a4
8ea6312
 
62058a4
 
8ea6312
 
 
 
 
 
 
 
 
 
 
 
 
b4a4d6e
62058a4
 
 
b4b3712
 
83c0537
2924e8e
 
 
 
 
b4b3712
 
83c0537
62058a4
 
 
 
 
 
88900ab
 
62058a4
83c0537
62058a4
5a2307a
62058a4
 
 
b4a4d6e
83c0537
62058a4
 
 
 
 
 
 
 
 
83c0537
 
 
 
 
 
 
6ae645e
88900ab
59bad6c
88900ab
7b4e84e
 
59bad6c
 
6ae645e
8ea6312
62058a4
 
 
b6fc770
474b075
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import gradio as gr
from model.analyzer import analyze_content
import asyncio
import time

# Custom CSS for dark theme, animations, and purple accent color
custom_css = """
* {
    font-family: 'Roboto', sans-serif;
}
.gradio-container {
    background: #121212 !important;
    color: #fff !important;
    overflow: hidden;
    transition: background 0.5s ease;
}
.treat-title {
    text-align: center;
    padding: 40px;
    margin-bottom: 30px;
    background: rgba(18, 18, 18, 0.85);
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    animation: slideInFromTop 1s ease-out;
}
.treat-title h1 {
    font-size: 5em;
    color: #4f46e5;
    margin-bottom: 10px;
    font-weight: bold;
    animation: fadeInText 1.5s ease-out;
}
.treat-title p {
    font-size: 1.3em;
    color: #4f46e5;
    animation: fadeInText 1.5s ease-out 0.5s;
}
.highlight {
    color: #4f46e5;
    font-weight: bold;
}
.content-area, .results-area {
    background: rgba(33, 33, 33, 0.9) !important;
    border-radius: 15px !important;
    padding: 30px !important;
    margin: 20px 0 !important;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5) !important;
    opacity: 0;
    animation: fadeInUp 1s forwards;
}
.gradio-textbox textarea {
    background-color: #333 !important;
    color: #fff !important;
    border: 1px solid #444 !important;
    border-radius: 8px !important;
    padding: 12px !important;
    font-size: 1.1em !important;
    transition: border-color 0.3s ease;
}
.gradio-textbox textarea:focus {
    border-color: #4f46e5 !important;
}
.gradio-button {
    background-color: #4f46e5 !important;
    color: white !important;
    border: none !important;
    border-radius: 25px !important;
    padding: 12px 24px !important;
    font-size: 1.2em !important;
    transition: transform 0.3s ease, background-color 0.3s ease;
    margin: 20px 0 !important;
}
.gradio-button:hover {
    transform: scale(1.1) !important;
    background-color: #5749d3 !important;
}
.gradio-button:active {
    transform: scale(0.98) !important;
    background-color: #4b40bb !important;
}
label {
    color: #ccc !important;
    font-weight: 500 !important;
    margin-bottom: 10px !important;
}
.center-row {
    display: flex;
    justify-content: center;
    align-items: center;
}
.footer {
    text-align: center;
    margin-top: 40px;
    font-size: 1.2em;
    color: #bdbdbd;
    opacity: 0;
    animation: fadeInUp 1s forwards 1.5s;
}
.footer p {
    color: #4f46e5;
}
footer {
   visibility: hidden;
}     
@keyframes slideInFromTop {
    0% { transform: translateY(-50px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}
@keyframes fadeInText {
    0% { opacity: 0; }
    100% { opacity: 1; }
}
@keyframes fadeInUp {
    0% { opacity: 0; transform: translateY(30px); }
    100% { opacity: 1; transform: translateY(0); }
}
"""

def analyze_with_loading(text, progress=gr.Progress()):
    """
    Synchronous wrapper for the async analyze_content function
    """
    # Initialize progress
    progress(0, desc="Starting analysis...")
    
    # Initial setup phase
    for i in range(30):
        time.sleep(0.02)  # Reduced sleep time
        progress((i + 1) / 100)
    
    # Perform analysis
    progress(0.3, desc="Processing text...")
    try:
        # Use asyncio.run to handle the async function call
        result = asyncio.run(analyze_content(text))
    except Exception as e:
        return f"Error during analysis: {str(e)}"
    
    # Final processing
    for i in range(70, 100):
        time.sleep(0.02)  # Reduced sleep time
        progress((i + 1) / 100)
    
    # Format the results
    triggers = result["detected_triggers"]
    if triggers == ["None"]:
        return "✓ No triggers detected in the content."
    else:
        trigger_list = "\n".join([f"• {trigger}" for trigger in triggers])
        return f"⚠ Triggers Detected:\n{trigger_list}"

# Create the Gradio interface
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
    # Title section
    gr.HTML("""
        <div class="treat-title">
            <h1>TREAT</h1>
            <p><span class="highlight">T</span>rigger 
               <span class="highlight">R</span>ecognition for 
               <span class="highlight">E</span>njoyable and 
               <span class="highlight">A</span>ppropriate 
               <span class="highlight">T</span>elevision</p>
        </div>
    """)
    
    # Content input section
    with gr.Row():
        with gr.Column(elem_classes="content-area"):
            input_text = gr.Textbox(
                label="Content to Analyze",
                placeholder="Paste your content here...",
                lines=8,
                interactive=True
            )
    
    # Button section
    with gr.Row(elem_classes="center-row"):
        analyze_btn = gr.Button(
            "✨ Analyze Content",
            variant="primary"
        )
    
    # Results section
    with gr.Row():
        with gr.Column(elem_classes="results-area"):
            output_text = gr.Textbox(
                label="Analysis Results",
                lines=5,
                interactive=False
            )
    
    # Set up the click event
    analyze_btn.click(
        fn=analyze_with_loading,
        inputs=[input_text],
        outputs=[output_text],
        api_name="analyze"
    )

    # Footer section
    gr.HTML("""
        <div class="footer">
            <p>Made with 💖 by Kuber Mehta</p>
        </div>
    """)

if __name__ == "__main__":
    # Launch without the 'ssr' argument
    iface.launch(
        share=False,
        debug=True,
        show_error=True
    )