Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -108,21 +108,34 @@ body { font-family: 'Open Sans', sans-serif !important; }
|
|
108 |
}
|
109 |
.model-selector {
|
110 |
display: flex;
|
111 |
-
gap:
|
112 |
margin-bottom: 1rem;
|
113 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
"""
|
115 |
|
116 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
117 |
gr.Markdown("# Brand Analyzer", elem_classes="text-2xl font-bold mb-2")
|
118 |
gr.Markdown("*Analyze text using interpretable neural features*", elem_classes="text-gray-600 mb-6")
|
119 |
|
|
|
120 |
features_state = gr.State([])
|
121 |
-
selected_model = gr.State("Gemini") # Default to Gemini
|
122 |
|
123 |
with gr.Row(elem_classes="model-selector"):
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
with gr.Row():
|
128 |
with gr.Column(scale=1):
|
@@ -138,46 +151,27 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
138 |
)
|
139 |
|
140 |
with gr.Column(scale=2):
|
141 |
-
|
142 |
-
def render_features(features, current_model):
|
143 |
-
if not features:
|
144 |
-
return
|
145 |
-
|
146 |
-
model = Model.GEMMA if current_model == "Gemini" else Model.GPT2
|
147 |
-
|
148 |
-
for token_group in features:
|
149 |
-
gr.Markdown(f"### {token_group['token']}")
|
150 |
-
with gr.Row():
|
151 |
-
for feature in token_group['features']:
|
152 |
-
btn = gr.Button(
|
153 |
-
f"Feature {feature['id']} (Activation: {feature['activation']:.2f})",
|
154 |
-
elem_classes=["feature-button"]
|
155 |
-
)
|
156 |
-
btn.click(
|
157 |
-
fn=lambda fid=feature['id']: handle_feature_click(fid, model),
|
158 |
-
outputs=dashboard
|
159 |
-
)
|
160 |
-
|
161 |
dashboard = gr.HTML()
|
162 |
|
163 |
-
def
|
164 |
-
return
|
165 |
|
166 |
-
|
167 |
-
fn=lambda:
|
168 |
-
|
169 |
-
|
170 |
)
|
171 |
|
172 |
-
|
173 |
-
fn=
|
174 |
-
|
175 |
-
|
176 |
)
|
177 |
|
178 |
-
|
179 |
-
fn=
|
180 |
-
inputs=[input_text,
|
181 |
outputs=[features_state, dashboard]
|
182 |
)
|
183 |
|
|
|
108 |
}
|
109 |
.model-selector {
|
110 |
display: flex;
|
111 |
+
gap: 0.5rem;
|
112 |
margin-bottom: 1rem;
|
113 |
}
|
114 |
+
.model-button {
|
115 |
+
padding: 0.25rem 0.75rem !important;
|
116 |
+
min-width: 0 !important;
|
117 |
+
height: 32px !important;
|
118 |
+
font-size: 0.875rem !important;
|
119 |
+
}
|
120 |
"""
|
121 |
|
122 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
123 |
gr.Markdown("# Brand Analyzer", elem_classes="text-2xl font-bold mb-2")
|
124 |
gr.Markdown("*Analyze text using interpretable neural features*", elem_classes="text-gray-600 mb-6")
|
125 |
|
126 |
+
current_model = gr.State("Gemini")
|
127 |
features_state = gr.State([])
|
|
|
128 |
|
129 |
with gr.Row(elem_classes="model-selector"):
|
130 |
+
with gr.Column(scale=1):
|
131 |
+
model_choice = gr.Radio(
|
132 |
+
choices=["Gemini", "OpenAI"],
|
133 |
+
value="Gemini",
|
134 |
+
label="Select Model",
|
135 |
+
elem_classes="model-buttons",
|
136 |
+
container=False,
|
137 |
+
interactive=True
|
138 |
+
)
|
139 |
|
140 |
with gr.Row():
|
141 |
with gr.Column(scale=1):
|
|
|
151 |
)
|
152 |
|
153 |
with gr.Column(scale=2):
|
154 |
+
features_list = gr.JSON(label="Features", visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
dashboard = gr.HTML()
|
156 |
|
157 |
+
def update_and_analyze(text, model):
|
158 |
+
return analyze_text(text, model)
|
159 |
|
160 |
+
model_choice.change(
|
161 |
+
fn=lambda x: x,
|
162 |
+
inputs=[model_choice],
|
163 |
+
outputs=[current_model]
|
164 |
)
|
165 |
|
166 |
+
analyze_btn.click(
|
167 |
+
fn=update_and_analyze,
|
168 |
+
inputs=[input_text, current_model],
|
169 |
+
outputs=[features_state, dashboard]
|
170 |
)
|
171 |
|
172 |
+
input_text.submit(
|
173 |
+
fn=update_and_analyze,
|
174 |
+
inputs=[input_text, current_model],
|
175 |
outputs=[features_state, dashboard]
|
176 |
)
|
177 |
|