workbykait commited on
Commit
bdd6f30
·
verified ·
1 Parent(s): 788e25a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -9
app.py CHANGED
@@ -5,7 +5,6 @@ import random
5
  from datetime import datetime, timedelta
6
  import plotly.express as px
7
  import re
8
- import io
9
 
10
  api_key = os.getenv("CEREBRAS_API_KEY")
11
  url = "https://api.cerebras.ai/v1/chat/completions"
@@ -44,7 +43,7 @@ def generate_random_log():
44
 
45
  def analyze_log(log_text):
46
  if not log_text.strip():
47
- return "Error: Please enter a log.", None, None, None
48
  LOG_HISTORY.append(log_text)
49
  data = {
50
  "model": "llama-4-scout-17b-16e-instruct",
@@ -82,10 +81,9 @@ def analyze_log(log_text):
82
  if time_match:
83
  times.append(time_match.group(1)[-5:])
84
  fig = px.line(x=times, y=signals, labels={"x": "Time", "y": "Signal (%)"}, title="Signal Trend") if signals and len(signals) == len(times) else None
85
- export_file = io.StringIO(summary)
86
- return summary, html, fig, gr.File(value=export_file, file_name="summary.txt", visible=True)
87
  except Exception as e:
88
- return f"Error: API call failed - {str(e)}", None, None, None
89
 
90
  def generate_alert(log_text):
91
  if not log_text.strip():
@@ -161,18 +159,15 @@ with gr.Blocks(css=css) as interface:
161
  analyze_button = gr.Button("Analyze")
162
  alert_button = gr.Button("Alert")
163
  compare_button = gr.Button("Compare Logs")
164
- export_button = gr.Button("Export")
165
  output = gr.HTML(show_label=False)
166
  plot_output = gr.Plot(show_label=False)
167
  alert_output = gr.HTML(show_label=False)
168
  compare_output = gr.HTML(show_label=False)
169
- export_output = gr.File(show_label=False, visible=False)
170
  sample_button.click(fn=load_sample_log, outputs=log_input)
171
  random_button.click(fn=generate_random_log, outputs=log_input)
172
  clear_button.click(fn=clear_log, outputs=log_input)
173
- analyze_button.click(fn=analyze_log, inputs=log_input, outputs=[output, output, plot_output, export_output])
174
  alert_button.click(fn=generate_alert, inputs=log_input, outputs=alert_output)
175
  compare_button.click(fn=compare_logs, outputs=[compare_output, compare_output])
176
- export_button.click(fn=lambda: None, outputs=export_output)
177
 
178
  interface.launch()
 
5
  from datetime import datetime, timedelta
6
  import plotly.express as px
7
  import re
 
8
 
9
  api_key = os.getenv("CEREBRAS_API_KEY")
10
  url = "https://api.cerebras.ai/v1/chat/completions"
 
43
 
44
  def analyze_log(log_text):
45
  if not log_text.strip():
46
+ return "Error: Please enter a log.", None, None
47
  LOG_HISTORY.append(log_text)
48
  data = {
49
  "model": "llama-4-scout-17b-16e-instruct",
 
81
  if time_match:
82
  times.append(time_match.group(1)[-5:])
83
  fig = px.line(x=times, y=signals, labels={"x": "Time", "y": "Signal (%)"}, title="Signal Trend") if signals and len(signals) == len(times) else None
84
+ return summary, html, fig
 
85
  except Exception as e:
86
+ return f"Error: API call failed - {str(e)}", None, None
87
 
88
  def generate_alert(log_text):
89
  if not log_text.strip():
 
159
  analyze_button = gr.Button("Analyze")
160
  alert_button = gr.Button("Alert")
161
  compare_button = gr.Button("Compare Logs")
 
162
  output = gr.HTML(show_label=False)
163
  plot_output = gr.Plot(show_label=False)
164
  alert_output = gr.HTML(show_label=False)
165
  compare_output = gr.HTML(show_label=False)
 
166
  sample_button.click(fn=load_sample_log, outputs=log_input)
167
  random_button.click(fn=generate_random_log, outputs=log_input)
168
  clear_button.click(fn=clear_log, outputs=log_input)
169
+ analyze_button.click(fn=analyze_log, inputs=log_input, outputs=[output, output, plot_output])
170
  alert_button.click(fn=generate_alert, inputs=log_input, outputs=alert_output)
171
  compare_button.click(fn=compare_logs, outputs=[compare_output, compare_output])
 
172
 
173
  interface.launch()