Kuberwastaken commited on
Commit
b4a4d6e
·
1 Parent(s): 481806b

Potentially better UI

Browse files
Files changed (2) hide show
  1. gradio_app.py +166 -8
  2. model/analyzer.py +3 -0
gradio_app.py CHANGED
@@ -1,14 +1,172 @@
1
  import gradio as gr
 
2
  from model.analyzer import analyze_content
3
 
4
- # Create and launch the Gradio interface
5
- iface = gr.Interface(
6
- fn=analyze_content,
7
- inputs=gr.Textbox(lines=8, label="Input Text"),
8
- outputs=gr.JSON(),
9
- title="Content Analysis",
10
- description="Analyze text content for sensitive topics"
11
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  if __name__ == "__main__":
14
  iface.launch()
 
1
  import gradio as gr
2
+ import time
3
  from model.analyzer import analyze_content
4
 
5
+ # Custom CSS for the interface
6
+ css = """
7
+ @import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700&display=swap');
8
+
9
+ #treat-container {
10
+ background: linear-gradient(135deg, #ffE6F0 0%, #E6F0FF 100%);
11
+ padding: 2rem;
12
+ border-radius: 20px;
13
+ box-shadow: 0 8px 32px rgba(0,0,0,0.1);
14
+ font-family: 'Nunito', sans-serif;
15
+ }
16
+
17
+ #treat-title {
18
+ text-align: center;
19
+ color: #FF69B4;
20
+ font-size: 3.5rem;
21
+ font-weight: bold;
22
+ margin-bottom: 0.5rem;
23
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
24
+ }
25
+
26
+ #treat-subtitle {
27
+ text-align: center;
28
+ color: #666;
29
+ font-size: 1.2rem;
30
+ margin-bottom: 2rem;
31
+ }
32
+
33
+ #treat-subtitle span {
34
+ color: #FF69B4;
35
+ font-weight: bold;
36
+ }
37
+
38
+ .content-box {
39
+ background: rgba(255,255,255,0.9);
40
+ border-radius: 15px;
41
+ border: 2px solid #FFB6C1;
42
+ padding: 1rem;
43
+ }
44
+
45
+ .analyze-button {
46
+ background: linear-gradient(45deg, #FF69B4, #87CEEB) !important;
47
+ border: none !important;
48
+ border-radius: 25px !important;
49
+ color: white !important;
50
+ font-family: 'Nunito', sans-serif !important;
51
+ font-weight: bold !important;
52
+ padding: 0.8rem 2rem !important;
53
+ transition: transform 0.2s !important;
54
+ }
55
+
56
+ .analyze-button:hover {
57
+ transform: translateY(-2px) !important;
58
+ }
59
+
60
+ .results-container {
61
+ background: rgba(255,255,255,0.9);
62
+ border-radius: 15px;
63
+ padding: 1.5rem;
64
+ margin-top: 1rem;
65
+ border: 2px solid #87CEEB;
66
+ }
67
+
68
+ #loading-bar {
69
+ height: 6px;
70
+ background: linear-gradient(90deg, #FF69B4, #87CEEB);
71
+ border-radius: 3px;
72
+ transition: width 0.3s ease;
73
+ }
74
+ """
75
+
76
+ def analyze_with_loading(text):
77
+ # Simulate loading progress (you can integrate this with your actual analysis)
78
+ for i in range(100):
79
+ time.sleep(0.02) # Simulate processing time
80
+ yield {"progress": i + 1}
81
+
82
+ # Perform the actual analysis
83
+ result = analyze_content(text)
84
+
85
+ # Format the results
86
+ if result["detected_triggers"] == ["None"]:
87
+ triggers_text = "No triggers detected"
88
+ else:
89
+ triggers_text = ", ".join(result["detected_triggers"])
90
+
91
+ yield {
92
+ "progress": 100,
93
+ "result": f"""
94
+ <div class='results-container'>
95
+ <h3 style='color: #FF69B4; margin-bottom: 1rem;'>Analysis Results</h3>
96
+ <p><strong>Triggers Detected:</strong> {triggers_text}</p>
97
+ <p><strong>Confidence:</strong> {result['confidence']}</p>
98
+ <p><strong>Analysis Time:</strong> {result['analysis_timestamp']}</p>
99
+ </div>
100
+ """
101
+ }
102
+
103
+ with gr.Blocks(css=css) as iface:
104
+ with gr.Column(elem_id="treat-container"):
105
+ gr.HTML("""
106
+ <div id="treat-title">TREAT</div>
107
+ <div id="treat-subtitle">
108
+ <span>T</span>rigger <span>R</span>ecognition for
109
+ <span>E</span>njoyable and <span>A</span>ppropriate
110
+ <span>T</span>elevision
111
+ </div>
112
+ """)
113
+
114
+ text_input = gr.Textbox(
115
+ label="Enter your content for analysis",
116
+ placeholder="Paste your script or content here...",
117
+ lines=8,
118
+ elem_classes=["content-box"]
119
+ )
120
+
121
+ analyze_btn = gr.Button(
122
+ "🍬 Analyze Content",
123
+ elem_classes=["analyze-button"]
124
+ )
125
+
126
+ progress = gr.Number(
127
+ value=0,
128
+ visible=False,
129
+ elem_id="progress-value"
130
+ )
131
+
132
+ gr.HTML("""
133
+ <div style="width: 100%; height: 6px; background: #eee; border-radius: 3px; margin: 1rem 0;">
134
+ <div id="loading-bar" style="width: 0%"></div>
135
+ </div>
136
+ """)
137
+
138
+ output = gr.HTML()
139
+
140
+ # JavaScript for updating the loading bar
141
+ gr.HTML("""
142
+ <script>
143
+ function updateLoadingBar(progress) {
144
+ document.getElementById('loading-bar').style.width = progress + '%';
145
+ }
146
+
147
+ // Watch for changes to the progress value
148
+ const observer = new MutationObserver((mutations) => {
149
+ mutations.forEach((mutation) => {
150
+ if (mutation.type === 'attributes' && mutation.attributeName === 'value') {
151
+ const progress = document.getElementById('progress-value').value;
152
+ updateLoadingBar(progress);
153
+ }
154
+ });
155
+ });
156
+
157
+ // Start observing the progress value element
158
+ observer.observe(document.getElementById('progress-value'), {
159
+ attributes: true
160
+ });
161
+ </script>
162
+ """)
163
+
164
+ analyze_btn.click(
165
+ fn=analyze_with_loading,
166
+ inputs=[text_input],
167
+ outputs=[gr.State({"progress": 0, "result": ""}), output],
168
+ show_progress=False
169
+ )
170
 
171
  if __name__ == "__main__":
172
  iface.launch()
model/analyzer.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import os
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
 
1
+ # analyzer.py
2
+ # model > analyzer.py
3
+
4
  import os
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
6
  import torch