Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,21 +59,29 @@ def analyze_log(log_text):
|
|
| 59 |
try:
|
| 60 |
response = requests.post(url, json=data, headers=headers)
|
| 61 |
summary = response.json()["choices"][0]["message"]["content"]
|
| 62 |
-
html = "<div style='font-family:
|
| 63 |
for line in summary.split("\n"):
|
| 64 |
if "Issues:" in line:
|
| 65 |
-
html += "<li><b style='color
|
| 66 |
elif "High-priority messages:" in line:
|
| 67 |
-
html += "</ul><li><b style='color
|
| 68 |
elif "Key details:" in line:
|
| 69 |
-
html += "</ul><li><b style='color
|
| 70 |
elif line.strip():
|
| 71 |
html += f"<li>{line.strip()}</li>"
|
| 72 |
html += "</ul></div>"
|
| 73 |
-
#
|
| 74 |
-
signals = [
|
| 75 |
-
times = [
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
return summary, html, fig
|
| 78 |
except Exception as e:
|
| 79 |
return f"Error: API call failed - {str(e)}", None, None
|
|
@@ -95,7 +103,7 @@ def generate_alert(log_text):
|
|
| 95 |
try:
|
| 96 |
response = requests.post(url, json=data, headers=headers)
|
| 97 |
alert = response.json()["choices"][0]["message"]["content"]
|
| 98 |
-
return f"<div style='
|
| 99 |
except Exception as e:
|
| 100 |
return f"Error: Alert failed - {str(e)}"
|
| 101 |
|
|
@@ -117,7 +125,7 @@ def compare_logs():
|
|
| 117 |
try:
|
| 118 |
response = requests.post(url, json=data, headers=headers)
|
| 119 |
comparison = response.json()["choices"][0]["message"]["content"]
|
| 120 |
-
html = "<div style='font-family:
|
| 121 |
for line in comparison.split("\n"):
|
| 122 |
if line.strip():
|
| 123 |
html += f"<li>{line.strip()}</li>"
|
|
@@ -132,22 +140,29 @@ def load_sample_log():
|
|
| 132 |
def clear_log():
|
| 133 |
return ""
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
with gr.Row():
|
| 140 |
-
sample_button = gr.Button("
|
| 141 |
-
random_button = gr.Button("
|
| 142 |
-
clear_button = gr.Button("Clear
|
| 143 |
with gr.Row():
|
| 144 |
analyze_button = gr.Button("Analyze")
|
| 145 |
-
alert_button = gr.Button("
|
| 146 |
-
compare_button = gr.Button("Compare
|
| 147 |
-
output = gr.HTML(
|
| 148 |
-
plot_output = gr.Plot(
|
| 149 |
-
alert_output = gr.HTML(
|
| 150 |
-
compare_output = gr.HTML(
|
| 151 |
sample_button.click(fn=load_sample_log, outputs=log_input)
|
| 152 |
random_button.click(fn=generate_random_log, outputs=log_input)
|
| 153 |
clear_button.click(fn=clear_log, outputs=log_input)
|
|
|
|
| 59 |
try:
|
| 60 |
response = requests.post(url, json=data, headers=headers)
|
| 61 |
summary = response.json()["choices"][0]["message"]["content"]
|
| 62 |
+
html = "<div style='font-family:Roboto; color:white; background:#333; padding:10px; border-radius:5px;'><h3>Analysis</h3><ul>"
|
| 63 |
for line in summary.split("\n"):
|
| 64 |
if "Issues:" in line:
|
| 65 |
+
html += "<li><b style='color:#ff6200;'>Issues:</b><ul>"
|
| 66 |
elif "High-priority messages:" in line:
|
| 67 |
+
html += "</ul><li><b style='color:#ff6200;'>Priority Alerts:</b><ul>"
|
| 68 |
elif "Key details:" in line:
|
| 69 |
+
html += "</ul><li><b style='color:#ff6200;'>Details:</b><ul>"
|
| 70 |
elif line.strip():
|
| 71 |
html += f"<li>{line.strip()}</li>"
|
| 72 |
html += "</ul></div>"
|
| 73 |
+
# Robust signal extraction
|
| 74 |
+
signals = []
|
| 75 |
+
times = []
|
| 76 |
+
for line in log_text.split("\n"):
|
| 77 |
+
if "Signal Strength" in line:
|
| 78 |
+
match = re.search(r"Signal Strength: (\d+)%", line)
|
| 79 |
+
if match:
|
| 80 |
+
signals.append(int(match.group(1)))
|
| 81 |
+
time_match = re.search(r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}) UTC", line)
|
| 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 |
return summary, html, fig
|
| 86 |
except Exception as e:
|
| 87 |
return f"Error: API call failed - {str(e)}", None, None
|
|
|
|
| 103 |
try:
|
| 104 |
response = requests.post(url, json=data, headers=headers)
|
| 105 |
alert = response.json()["choices"][0]["message"]["content"]
|
| 106 |
+
return f"<div style='font-family:Roboto; background:#ff6200; color:black; padding:10px; border-radius:5px;'>{alert}</div>"
|
| 107 |
except Exception as e:
|
| 108 |
return f"Error: Alert failed - {str(e)}"
|
| 109 |
|
|
|
|
| 125 |
try:
|
| 126 |
response = requests.post(url, json=data, headers=headers)
|
| 127 |
comparison = response.json()["choices"][0]["message"]["content"]
|
| 128 |
+
html = "<div style='font-family:Roboto; color:white; background:#333; padding:10px; border-radius:5px;'><h3>Comparison</h3><ul>"
|
| 129 |
for line in comparison.split("\n"):
|
| 130 |
if line.strip():
|
| 131 |
html += f"<li>{line.strip()}</li>"
|
|
|
|
| 140 |
def clear_log():
|
| 141 |
return ""
|
| 142 |
|
| 143 |
+
css = """
|
| 144 |
+
body, .gradio-container { background: black; color: white; font-family: Roboto, sans-serif; }
|
| 145 |
+
button { background: #ff6200; color: black; border: none; padding: 8px 16px; border-radius: 5px; }
|
| 146 |
+
button:hover { background: #e55a00; }
|
| 147 |
+
.input-text, .output-text { background: #333; color: white; border: 1px solid #ff6200; border-radius: 5px; }
|
| 148 |
+
h3 { color: #ff6200; }
|
| 149 |
+
"""
|
| 150 |
+
with gr.Blocks(css=css) as interface:
|
| 151 |
+
gr.Markdown("# Satellite Signal Log Analyzer", elem_classes="header")
|
| 152 |
+
gr.Markdown("Analyze logs for issues, alerts, and trends.", elem_classes="subheader")
|
| 153 |
+
log_input = gr.Textbox(lines=5, show_label=False, placeholder="Enter or generate a log...")
|
| 154 |
with gr.Row():
|
| 155 |
+
sample_button = gr.Button("Sample Log")
|
| 156 |
+
random_button = gr.Button("Random Log")
|
| 157 |
+
clear_button = gr.Button("Clear")
|
| 158 |
with gr.Row():
|
| 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)
|