Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,6 @@ matplotlib.use('Agg') # Set backend for Matplotlib to avoid GUI conflicts with G
|
|
7 |
import matplotlib.pyplot as plt
|
8 |
import time # For profiling if needed
|
9 |
|
10 |
-
# --- Add Gemini Import ---
|
11 |
-
from google import genai
|
12 |
-
|
13 |
# --- Module Imports ---
|
14 |
from gradio_utils import get_url_user_token
|
15 |
|
@@ -163,44 +160,6 @@ def update_analytics_plots_figures(token_state_value, date_filter_option, custom
|
|
163 |
return [error_msg] + placeholder_figs
|
164 |
|
165 |
|
166 |
-
# --- Gemini Test Function (simple as requested, with prompt input) ---
|
167 |
-
def call_gemini_api_direct_with_prompt(user_prompt):
|
168 |
-
"""
|
169 |
-
Calls the Gemini API with the provided prompt and API key.
|
170 |
-
This function performs a direct API call without explicit try-except blocks
|
171 |
-
for the API interaction itself, as per the request.
|
172 |
-
"""
|
173 |
-
# WARNING: Hardcoding API keys is not recommended for production.
|
174 |
-
# Consider using environment variables or a secure config management system.
|
175 |
-
api_key = "AIzaSyCSfIw2kWWO1c_oa7WQ33h11O6N8egNoqk" # User provided API key
|
176 |
-
|
177 |
-
if not user_prompt:
|
178 |
-
logging.warning("Gemini API call: Prompt is empty.")
|
179 |
-
return "Per favore, inserisci un prompt."
|
180 |
-
|
181 |
-
try:
|
182 |
-
# Configure the genai library with the API key
|
183 |
-
|
184 |
-
# Specify the model name as requested
|
185 |
-
model_name = "gemini-2.5-flash-preview-05-20"
|
186 |
-
|
187 |
-
client = genai.Client(api_key="AIzaSyCSfIw2kWWO1c_oa7WQ33h11O6N8egNoqk")
|
188 |
-
|
189 |
-
response = client.models.generate_content(
|
190 |
-
model=model_name, contents="Explain how AI works in a few words"
|
191 |
-
)
|
192 |
-
|
193 |
-
# Log the response text (optional, for server-side debugging)
|
194 |
-
logging.info(f"Gemini API call successful. Prompt: . Response: '{response.text[:100]}...'")
|
195 |
-
|
196 |
-
return response.text
|
197 |
-
except Exception as e:
|
198 |
-
# Catching exceptions here to provide a user-friendly message in the UI
|
199 |
-
# instead of letting the Gradio app crash or show a raw error.
|
200 |
-
logging.error(f"Error calling Gemini API: {e}", exc_info=True)
|
201 |
-
return f"Errore durante la chiamata API Gemini: {str(e)}"
|
202 |
-
|
203 |
-
|
204 |
# --- Gradio UI Blocks ---
|
205 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
206 |
title="LinkedIn Organization Dashboard") as app:
|
@@ -234,37 +193,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
234 |
sync_status_html_output = gr.HTML("<p style='text-align:center;'>Stato sincronizzazione...</p>")
|
235 |
dashboard_display_html = gr.HTML("<p style='text-align:center;'>Caricamento dashboard...</p>")
|
236 |
|
237 |
-
# --- Gemini API Test Section ---
|
238 |
-
gr.Markdown("---") # Visual separator
|
239 |
-
gr.Markdown("## 🧪 Test Gemini API (Semplice)")
|
240 |
-
gr.Markdown("Inserisci un prompt e clicca il pulsante per testare la chiamata all'API Gemini.")
|
241 |
-
|
242 |
-
with gr.Row():
|
243 |
-
gemini_test_prompt_input = gr.Textbox(
|
244 |
-
label="Prompt per Gemini:",
|
245 |
-
value="Explain how AI works in a few words",
|
246 |
-
lines=2,
|
247 |
-
scale=3
|
248 |
-
)
|
249 |
-
gemini_test_btn = gr.Button("🚀 Esegui Test Gemini", scale=1, variant="secondary")
|
250 |
-
|
251 |
-
gemini_output_textbox = gr.Textbox(
|
252 |
-
label="Risposta da Gemini:",
|
253 |
-
interactive=False,
|
254 |
-
lines=5,
|
255 |
-
show_label=True,
|
256 |
-
placeholder="La risposta di Gemini apparirà qui..."
|
257 |
-
)
|
258 |
-
|
259 |
-
# Connect the button to the Gemini API call function
|
260 |
-
gemini_test_btn.click(
|
261 |
-
fn=call_gemini_api_direct_with_prompt,
|
262 |
-
inputs=[gemini_test_prompt_input],
|
263 |
-
outputs=[gemini_output_textbox],
|
264 |
-
api_name="test_gemini_simple" # Optional: for API access if needed by Gradio client
|
265 |
-
)
|
266 |
-
# --- End Gemini API Test Section ---
|
267 |
-
|
268 |
org_urn_display.change(
|
269 |
fn=initial_load_sequence,
|
270 |
inputs=[url_user_token_display, org_urn_display, token_state],
|
@@ -615,6 +543,4 @@ if __name__ == "__main__":
|
|
615 |
except ImportError:
|
616 |
logging.error("Matplotlib non è installato. I grafici non verranno generati.")
|
617 |
|
618 |
-
|
619 |
-
# pip install google-generativeai
|
620 |
-
app.launch(server_name="0.0.0.0", server_port=7860, debug=True)
|
|
|
7 |
import matplotlib.pyplot as plt
|
8 |
import time # For profiling if needed
|
9 |
|
|
|
|
|
|
|
10 |
# --- Module Imports ---
|
11 |
from gradio_utils import get_url_user_token
|
12 |
|
|
|
160 |
return [error_msg] + placeholder_figs
|
161 |
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
# --- Gradio UI Blocks ---
|
164 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
165 |
title="LinkedIn Organization Dashboard") as app:
|
|
|
193 |
sync_status_html_output = gr.HTML("<p style='text-align:center;'>Stato sincronizzazione...</p>")
|
194 |
dashboard_display_html = gr.HTML("<p style='text-align:center;'>Caricamento dashboard...</p>")
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
org_urn_display.change(
|
197 |
fn=initial_load_sequence,
|
198 |
inputs=[url_user_token_display, org_urn_display, token_state],
|
|
|
543 |
except ImportError:
|
544 |
logging.error("Matplotlib non è installato. I grafici non verranno generati.")
|
545 |
|
546 |
+
app.launch(server_name="0.0.0.0", server_port=7860, debug=True)
|
|
|
|