Spaces:
Running
Running
Commit
·
e5b66ad
1
Parent(s):
11e3d09
Improved UI and animations :)
Browse files- gradio_app.py +122 -23
gradio_app.py
CHANGED
@@ -3,16 +3,16 @@ from model.analyzer import analyze_content
|
|
3 |
import asyncio
|
4 |
import time
|
5 |
|
6 |
-
# Custom CSS for dark theme, animations, and purple accent color
|
7 |
custom_css = """
|
8 |
* {
|
9 |
font-family: 'Roboto', sans-serif;
|
|
|
10 |
}
|
11 |
.gradio-container {
|
12 |
background: #121212 !important;
|
13 |
color: #fff !important;
|
14 |
overflow: hidden;
|
15 |
-
transition:
|
16 |
}
|
17 |
.treat-title {
|
18 |
text-align: center;
|
@@ -22,6 +22,11 @@ custom_css = """
|
|
22 |
border-radius: 15px;
|
23 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
24 |
animation: slideInFromTop 1s ease-out;
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
.treat-title h1 {
|
27 |
font-size: 5em;
|
@@ -29,6 +34,10 @@ custom_css = """
|
|
29 |
margin-bottom: 10px;
|
30 |
font-weight: bold;
|
31 |
animation: fadeInText 1.5s ease-out;
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
.treat-title p {
|
34 |
font-size: 1.3em;
|
@@ -38,6 +47,12 @@ custom_css = """
|
|
38 |
.highlight {
|
39 |
color: #4f46e5;
|
40 |
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
}
|
42 |
.content-area, .results-area {
|
43 |
background: rgba(33, 33, 33, 0.9) !important;
|
@@ -47,6 +62,11 @@ custom_css = """
|
|
47 |
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5) !important;
|
48 |
opacity: 0;
|
49 |
animation: fadeInUp 1s forwards;
|
|
|
|
|
|
|
|
|
|
|
50 |
}
|
51 |
.gradio-textbox textarea {
|
52 |
background-color: #333 !important;
|
@@ -55,10 +75,16 @@ custom_css = """
|
|
55 |
border-radius: 8px !important;
|
56 |
padding: 12px !important;
|
57 |
font-size: 1.1em !important;
|
58 |
-
transition:
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
.gradio-textbox textarea:focus {
|
61 |
border-color: #4f46e5 !important;
|
|
|
|
|
62 |
}
|
63 |
.gradio-button {
|
64 |
background-color: #4f46e5 !important;
|
@@ -67,21 +93,44 @@ custom_css = """
|
|
67 |
border-radius: 25px !important;
|
68 |
padding: 12px 24px !important;
|
69 |
font-size: 1.2em !important;
|
70 |
-
transition:
|
71 |
margin: 20px 0 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
.gradio-button:hover {
|
74 |
-
transform: scale(1.
|
75 |
background-color: #5749d3 !important;
|
|
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
.gradio-button:active {
|
78 |
-
transform: scale(0.98)
|
79 |
background-color: #4b40bb !important;
|
80 |
}
|
81 |
label {
|
82 |
color: #ccc !important;
|
83 |
font-weight: 500 !important;
|
84 |
margin-bottom: 10px !important;
|
|
|
|
|
|
|
|
|
85 |
}
|
86 |
.center-row {
|
87 |
display: flex;
|
@@ -95,51 +144,102 @@ label {
|
|
95 |
color: #bdbdbd;
|
96 |
opacity: 0;
|
97 |
animation: fadeInUp 1s forwards 1.5s;
|
|
|
|
|
|
|
|
|
98 |
}
|
99 |
.footer p {
|
100 |
color: #4f46e5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
footer {
|
103 |
-
|
104 |
}
|
|
|
105 |
@keyframes slideInFromTop {
|
106 |
0% { transform: translateY(-50px); opacity: 0; }
|
107 |
100% { transform: translateY(0); opacity: 1; }
|
108 |
}
|
109 |
@keyframes fadeInText {
|
110 |
-
0% { opacity: 0; }
|
111 |
-
100% { opacity: 1; }
|
112 |
}
|
113 |
@keyframes fadeInUp {
|
114 |
0% { opacity: 0; transform: translateY(30px); }
|
115 |
100% { opacity: 1; transform: translateY(0); }
|
116 |
}
|
|
|
|
|
|
|
|
|
|
|
117 |
"""
|
118 |
|
119 |
def analyze_with_loading(text, progress=gr.Progress()):
|
120 |
"""
|
121 |
-
Synchronous wrapper for the async analyze_content function
|
122 |
"""
|
123 |
# Initialize progress
|
124 |
progress(0, desc="Starting analysis...")
|
125 |
|
126 |
-
# Initial setup phase
|
127 |
-
for i in range(
|
128 |
-
time.sleep(0.
|
129 |
-
progress((i + 1) / 100)
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
# Perform analysis
|
132 |
-
progress(0.
|
133 |
try:
|
134 |
-
# Use asyncio.run to handle the async function call
|
135 |
result = asyncio.run(analyze_content(text))
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
except Exception as e:
|
137 |
return f"Error during analysis: {str(e)}"
|
138 |
|
139 |
-
# Final processing
|
140 |
-
for i in range(
|
141 |
-
time.sleep(0.02)
|
142 |
-
progress((i + 1) / 100)
|
143 |
|
144 |
# Format the results
|
145 |
triggers = result["detected_triggers"]
|
@@ -197,15 +297,14 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
197 |
api_name="analyze"
|
198 |
)
|
199 |
|
200 |
-
|
201 |
gr.HTML("""
|
202 |
<div class="footer">
|
203 |
-
<p>Made with
|
204 |
</div>
|
205 |
""")
|
206 |
|
207 |
if __name__ == "__main__":
|
208 |
-
# Launch without the 'ssr' argument
|
209 |
iface.launch(
|
210 |
share=False,
|
211 |
debug=True,
|
|
|
3 |
import asyncio
|
4 |
import time
|
5 |
|
|
|
6 |
custom_css = """
|
7 |
* {
|
8 |
font-family: 'Roboto', sans-serif;
|
9 |
+
transition: all 0.3s ease;
|
10 |
}
|
11 |
.gradio-container {
|
12 |
background: #121212 !important;
|
13 |
color: #fff !important;
|
14 |
overflow: hidden;
|
15 |
+
transition: all 0.5s ease;
|
16 |
}
|
17 |
.treat-title {
|
18 |
text-align: center;
|
|
|
22 |
border-radius: 15px;
|
23 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
24 |
animation: slideInFromTop 1s ease-out;
|
25 |
+
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
26 |
+
}
|
27 |
+
.treat-title:hover {
|
28 |
+
transform: translateY(-5px);
|
29 |
+
box-shadow: 0 8px 16px rgba(79, 70, 229, 0.3);
|
30 |
}
|
31 |
.treat-title h1 {
|
32 |
font-size: 5em;
|
|
|
34 |
margin-bottom: 10px;
|
35 |
font-weight: bold;
|
36 |
animation: fadeInText 1.5s ease-out;
|
37 |
+
transition: color 0.3s ease;
|
38 |
+
}
|
39 |
+
.treat-title:hover h1 {
|
40 |
+
color: #5749d3;
|
41 |
}
|
42 |
.treat-title p {
|
43 |
font-size: 1.3em;
|
|
|
47 |
.highlight {
|
48 |
color: #4f46e5;
|
49 |
font-weight: bold;
|
50 |
+
transition: color 0.3s ease, transform 0.3s ease;
|
51 |
+
display: inline-block;
|
52 |
+
}
|
53 |
+
.highlight:hover {
|
54 |
+
color: #5749d3;
|
55 |
+
transform: scale(1.1);
|
56 |
}
|
57 |
.content-area, .results-area {
|
58 |
background: rgba(33, 33, 33, 0.9) !important;
|
|
|
62 |
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5) !important;
|
63 |
opacity: 0;
|
64 |
animation: fadeInUp 1s forwards;
|
65 |
+
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
66 |
+
}
|
67 |
+
.content-area:hover, .results-area:hover {
|
68 |
+
transform: translateY(-3px);
|
69 |
+
box-shadow: 0 8px 16px rgba(79, 70, 229, 0.2) !important;
|
70 |
}
|
71 |
.gradio-textbox textarea {
|
72 |
background-color: #333 !important;
|
|
|
75 |
border-radius: 8px !important;
|
76 |
padding: 12px !important;
|
77 |
font-size: 1.1em !important;
|
78 |
+
transition: all 0.3s ease;
|
79 |
+
}
|
80 |
+
.gradio-textbox textarea:hover {
|
81 |
+
border-color: #4f46e5 !important;
|
82 |
+
box-shadow: 0 0 10px rgba(79, 70, 229, 0.2) !important;
|
83 |
}
|
84 |
.gradio-textbox textarea:focus {
|
85 |
border-color: #4f46e5 !important;
|
86 |
+
box-shadow: 0 0 15px rgba(79, 70, 229, 0.3) !important;
|
87 |
+
transform: translateY(-2px);
|
88 |
}
|
89 |
.gradio-button {
|
90 |
background-color: #4f46e5 !important;
|
|
|
93 |
border-radius: 25px !important;
|
94 |
padding: 12px 24px !important;
|
95 |
font-size: 1.2em !important;
|
96 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
97 |
margin: 20px 0 !important;
|
98 |
+
position: relative;
|
99 |
+
overflow: hidden;
|
100 |
+
}
|
101 |
+
.gradio-button::before {
|
102 |
+
content: '';
|
103 |
+
position: absolute;
|
104 |
+
top: 50%;
|
105 |
+
left: 50%;
|
106 |
+
width: 0;
|
107 |
+
height: 0;
|
108 |
+
background: rgba(255, 255, 255, 0.2);
|
109 |
+
border-radius: 50%;
|
110 |
+
transform: translate(-50%, -50%);
|
111 |
+
transition: width 0.6s ease, height 0.6s ease;
|
112 |
}
|
113 |
.gradio-button:hover {
|
114 |
+
transform: scale(1.05) translateY(-2px);
|
115 |
background-color: #5749d3 !important;
|
116 |
+
box-shadow: 0 6px 15px rgba(79, 70, 229, 0.4);
|
117 |
+
}
|
118 |
+
.gradio-button:hover::before {
|
119 |
+
width: 300px;
|
120 |
+
height: 300px;
|
121 |
}
|
122 |
.gradio-button:active {
|
123 |
+
transform: scale(0.98) translateY(1px);
|
124 |
background-color: #4b40bb !important;
|
125 |
}
|
126 |
label {
|
127 |
color: #ccc !important;
|
128 |
font-weight: 500 !important;
|
129 |
margin-bottom: 10px !important;
|
130 |
+
transition: color 0.3s ease;
|
131 |
+
}
|
132 |
+
label:hover {
|
133 |
+
color: #fff !important;
|
134 |
}
|
135 |
.center-row {
|
136 |
display: flex;
|
|
|
144 |
color: #bdbdbd;
|
145 |
opacity: 0;
|
146 |
animation: fadeInUp 1s forwards 1.5s;
|
147 |
+
transition: all 0.3s ease;
|
148 |
+
}
|
149 |
+
.footer:hover {
|
150 |
+
transform: translateY(-3px);
|
151 |
}
|
152 |
.footer p {
|
153 |
color: #4f46e5;
|
154 |
+
transition: all 0.3s ease;
|
155 |
+
}
|
156 |
+
.footer .heart {
|
157 |
+
display: inline-block;
|
158 |
+
transition: transform 0.3s ease;
|
159 |
+
animation: pulse 1.5s infinite;
|
160 |
+
}
|
161 |
+
.footer:hover .heart {
|
162 |
+
transform: scale(1.3);
|
163 |
+
}
|
164 |
+
.footer a {
|
165 |
+
color: #4f46e5;
|
166 |
+
text-decoration: none;
|
167 |
+
position: relative;
|
168 |
+
transition: all 0.3s ease;
|
169 |
+
}
|
170 |
+
.footer a:hover {
|
171 |
+
color: #5749d3;
|
172 |
+
}
|
173 |
+
.footer a::after {
|
174 |
+
content: '';
|
175 |
+
position: absolute;
|
176 |
+
width: 0;
|
177 |
+
height: 2px;
|
178 |
+
bottom: -2px;
|
179 |
+
left: 0;
|
180 |
+
background-color: #5749d3;
|
181 |
+
transition: width 0.3s ease;
|
182 |
+
}
|
183 |
+
.footer a:hover::after {
|
184 |
+
width: 100%;
|
185 |
}
|
186 |
footer {
|
187 |
+
visibility: hidden;
|
188 |
}
|
189 |
+
|
190 |
@keyframes slideInFromTop {
|
191 |
0% { transform: translateY(-50px); opacity: 0; }
|
192 |
100% { transform: translateY(0); opacity: 1; }
|
193 |
}
|
194 |
@keyframes fadeInText {
|
195 |
+
0% { opacity: 0; transform: translateY(10px); }
|
196 |
+
100% { opacity: 1; transform: translateY(0); }
|
197 |
}
|
198 |
@keyframes fadeInUp {
|
199 |
0% { opacity: 0; transform: translateY(30px); }
|
200 |
100% { opacity: 1; transform: translateY(0); }
|
201 |
}
|
202 |
+
@keyframes pulse {
|
203 |
+
0% { transform: scale(1); }
|
204 |
+
50% { transform: scale(1.2); }
|
205 |
+
100% { transform: scale(1); }
|
206 |
+
}
|
207 |
"""
|
208 |
|
209 |
def analyze_with_loading(text, progress=gr.Progress()):
|
210 |
"""
|
211 |
+
Synchronous wrapper for the async analyze_content function with smooth progress updates
|
212 |
"""
|
213 |
# Initialize progress
|
214 |
progress(0, desc="Starting analysis...")
|
215 |
|
216 |
+
# Initial setup phase - smoother progression
|
217 |
+
for i in range(25):
|
218 |
+
time.sleep(0.04) # Slightly longer sleep for smoother animation
|
219 |
+
progress((i + 1) / 100, desc="Initializing analysis...")
|
220 |
+
|
221 |
+
# Pre-processing phase
|
222 |
+
for i in range(25, 45):
|
223 |
+
time.sleep(0.03)
|
224 |
+
progress((i + 1) / 100, desc="Pre-processing content...")
|
225 |
|
226 |
# Perform analysis
|
227 |
+
progress(0.45, desc="Analyzing content...")
|
228 |
try:
|
|
|
229 |
result = asyncio.run(analyze_content(text))
|
230 |
+
|
231 |
+
# Analysis progress simulation
|
232 |
+
for i in range(45, 75):
|
233 |
+
time.sleep(0.03)
|
234 |
+
progress((i + 1) / 100, desc="Processing results...")
|
235 |
+
|
236 |
except Exception as e:
|
237 |
return f"Error during analysis: {str(e)}"
|
238 |
|
239 |
+
# Final processing with smooth progression
|
240 |
+
for i in range(75, 100):
|
241 |
+
time.sleep(0.02)
|
242 |
+
progress((i + 1) / 100, desc="Finalizing results...")
|
243 |
|
244 |
# Format the results
|
245 |
triggers = result["detected_triggers"]
|
|
|
297 |
api_name="analyze"
|
298 |
)
|
299 |
|
300 |
+
# Footer section
|
301 |
gr.HTML("""
|
302 |
<div class="footer">
|
303 |
+
<p>Made with <span class="heart">💖</span> by <a href="https://www.linkedin.com/in/kubermehta/" target="_blank">Kuber Mehta</a></p>
|
304 |
</div>
|
305 |
""")
|
306 |
|
307 |
if __name__ == "__main__":
|
|
|
308 |
iface.launch(
|
309 |
share=False,
|
310 |
debug=True,
|