Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,31 +42,16 @@ def generate_random_log():
|
|
42 |
entries.append(f"{time} | {lat}N, {lon}W | Frequency: {freq} GHz | Signal Strength: {signal}% | Message: {message}")
|
43 |
return "\n".join(entries)
|
44 |
|
45 |
-
def
|
46 |
if not log_text.strip():
|
47 |
-
return
|
48 |
-
|
49 |
-
for line in log_text.split("\n"):
|
50 |
-
match = re.search(r"Frequency: (\d+\.\d) GHz", line)
|
51 |
-
if match:
|
52 |
-
freq = float(match.group(1))
|
53 |
-
if min_freq <= freq <= max_freq:
|
54 |
-
filtered.append(line)
|
55 |
-
else:
|
56 |
-
filtered.append(line) # Keep non-frequency lines
|
57 |
-
return "\n".join(filtered) if filtered else "No logs in frequency range."
|
58 |
-
|
59 |
-
def analyze_log(log_text, min_freq, max_freq):
|
60 |
-
filtered_log = filter_log_by_frequency(log_text, min_freq, max_freq)
|
61 |
-
if not filtered_log.strip() or filtered_log.startswith("No logs"):
|
62 |
-
return filtered_log, None, None, None
|
63 |
-
LOG_HISTORY.append(filtered_log)
|
64 |
data = {
|
65 |
"model": "llama-4-scout-17b-16e-instruct",
|
66 |
"messages": [
|
67 |
{
|
68 |
"role": "user",
|
69 |
-
"content": "Analyze this satellite radio log and summarize in bullet points. Include interference risk scores (0-100, low signal <70% = high risk >80, emergency = 90). Ensure frequencies in issues and details:\n- Issues (e.g., low signal, noise, interference with frequency, risk score)\n- High-priority messages (e.g., emergencies, warnings)\n- Key details (coordinates, times, frequencies, signal strengths)\nLog:\n" +
|
70 |
}
|
71 |
],
|
72 |
"max_completion_tokens": 500,
|
@@ -88,7 +73,7 @@ def analyze_log(log_text, min_freq, max_freq):
|
|
88 |
html += "</ul></div>"
|
89 |
signals = []
|
90 |
times = []
|
91 |
-
for line in
|
92 |
if "Signal Strength" in line:
|
93 |
match = re.search(r"Signal Strength: (\d+)%", line)
|
94 |
if match:
|
@@ -168,7 +153,6 @@ with gr.Blocks(css=css) as interface:
|
|
168 |
gr.Markdown("# Satellite Signal Log Analyzer", elem_classes="header")
|
169 |
gr.Markdown("Analyze logs for issues, alerts, and trends.", elem_classes="subheader")
|
170 |
log_input = gr.Textbox(lines=5, show_label=False, placeholder="Enter or generate a log...")
|
171 |
-
freq_slider = gr.Slider(minimum=14.0, maximum=15.0, step=0.1, value=[14.0, 15.0], label="Frequency Range (GHz)")
|
172 |
with gr.Row():
|
173 |
sample_button = gr.Button("Sample Log")
|
174 |
random_button = gr.Button("Random Log")
|
@@ -186,7 +170,7 @@ with gr.Blocks(css=css) as interface:
|
|
186 |
sample_button.click(fn=load_sample_log, outputs=log_input)
|
187 |
random_button.click(fn=generate_random_log, outputs=log_input)
|
188 |
clear_button.click(fn=clear_log, outputs=log_input)
|
189 |
-
analyze_button.click(fn=analyze_log, inputs=
|
190 |
alert_button.click(fn=generate_alert, inputs=log_input, outputs=alert_output)
|
191 |
compare_button.click(fn=compare_logs, outputs=[compare_output, compare_output])
|
192 |
export_button.click(fn=lambda: None, outputs=export_output)
|
|
|
42 |
entries.append(f"{time} | {lat}N, {lon}W | Frequency: {freq} GHz | Signal Strength: {signal}% | Message: {message}")
|
43 |
return "\n".join(entries)
|
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",
|
51 |
"messages": [
|
52 |
{
|
53 |
"role": "user",
|
54 |
+
"content": "Analyze this satellite radio log and summarize in bullet points. Include interference risk scores (0-100, low signal <70% = high risk >80, emergency = 90). Ensure frequencies in issues and details:\n- Issues (e.g., low signal, noise, interference with frequency, risk score)\n- High-priority messages (e.g., emergencies, warnings)\n- Key details (coordinates, times, frequencies, signal strengths)\nLog:\n" + log_text
|
55 |
}
|
56 |
],
|
57 |
"max_completion_tokens": 500,
|
|
|
73 |
html += "</ul></div>"
|
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:
|
|
|
153 |
gr.Markdown("# Satellite Signal Log Analyzer", elem_classes="header")
|
154 |
gr.Markdown("Analyze logs for issues, alerts, and trends.", elem_classes="subheader")
|
155 |
log_input = gr.Textbox(lines=5, show_label=False, placeholder="Enter or generate a log...")
|
|
|
156 |
with gr.Row():
|
157 |
sample_button = gr.Button("Sample Log")
|
158 |
random_button = gr.Button("Random Log")
|
|
|
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)
|