Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
import os
|
4 |
import random
|
5 |
from datetime import datetime, timedelta
|
|
|
6 |
|
7 |
api_key = os.getenv("CEREBRAS_API_KEY")
|
8 |
url = "https://api.cerebras.ai/v1/chat/completions"
|
@@ -17,7 +18,6 @@ SAMPLE_LOG = """
|
|
17 |
2025-04-12 10:03 UTC | 40.9N, 74.2W | Frequency: 14.6 GHz | Signal Strength: 90% | Message: Emergency: Low battery alert.
|
18 |
"""
|
19 |
|
20 |
-
# Store logs for comparison
|
21 |
LOG_HISTORY = []
|
22 |
|
23 |
def generate_random_log():
|
@@ -42,7 +42,7 @@ def generate_random_log():
|
|
42 |
|
43 |
def analyze_log(log_text):
|
44 |
if not log_text.strip():
|
45 |
-
return "Error: Please enter a log.", None
|
46 |
LOG_HISTORY.append(log_text)
|
47 |
data = {
|
48 |
"model": "llama-4-scout-17b-16e-instruct",
|
@@ -58,7 +58,6 @@ def analyze_log(log_text):
|
|
58 |
try:
|
59 |
response = requests.post(url, json=data, headers=headers)
|
60 |
summary = response.json()["choices"][0]["message"]["content"]
|
61 |
-
# Format as HTML table
|
62 |
html = "<div style='font-family:Arial;'><h3>Analysis Summary</h3><ul>"
|
63 |
for line in summary.split("\n"):
|
64 |
if "Issues:" in line:
|
@@ -70,9 +69,13 @@ def analyze_log(log_text):
|
|
70 |
elif line.strip():
|
71 |
html += f"<li>{line.strip()}</li>"
|
72 |
html += "</ul></div>"
|
73 |
-
|
|
|
|
|
|
|
|
|
74 |
except Exception as e:
|
75 |
-
return f"Error: API call failed - {str(e)}", None
|
76 |
|
77 |
def generate_alert(log_text):
|
78 |
if not log_text.strip():
|
@@ -107,7 +110,7 @@ def compare_logs():
|
|
107 |
"content": "Compare these two satellite radio logs and summarize trends in bullet points (e.g., signal strength changes, frequency issues, new emergencies):\n" + compare_text
|
108 |
}
|
109 |
],
|
110 |
-
"max_completion_tokens":
|
111 |
"temperature": 0.5
|
112 |
}
|
113 |
try:
|
@@ -130,7 +133,7 @@ def clear_log():
|
|
130 |
|
131 |
with gr.Blocks(theme="huggingface/dark") as interface:
|
132 |
gr.Markdown("# Satellite Signal Log Analyzer")
|
133 |
-
gr.Markdown("Analyze satellite radio logs for issues, alerts, and
|
134 |
log_input = gr.Textbox(lines=5, label="Satellite Radio Log")
|
135 |
with gr.Row():
|
136 |
sample_button = gr.Button("Load Sample Log")
|
@@ -141,12 +144,13 @@ with gr.Blocks(theme="huggingface/dark") as interface:
|
|
141 |
alert_button = gr.Button("Generate Alert")
|
142 |
compare_button = gr.Button("Compare Last Two Logs")
|
143 |
output = gr.HTML(label="Analysis Summary")
|
|
|
144 |
alert_output = gr.HTML(label="Satellite Alert")
|
145 |
compare_output = gr.HTML(label="Log Comparison")
|
146 |
sample_button.click(fn=load_sample_log, outputs=log_input)
|
147 |
random_button.click(fn=generate_random_log, outputs=log_input)
|
148 |
clear_button.click(fn=clear_log, outputs=log_input)
|
149 |
-
analyze_button.click(fn=analyze_log, inputs=log_input, outputs=[output, output])
|
150 |
alert_button.click(fn=generate_alert, inputs=log_input, outputs=alert_output)
|
151 |
compare_button.click(fn=compare_logs, outputs=[compare_output, compare_output])
|
152 |
|
|
|
3 |
import os
|
4 |
import random
|
5 |
from datetime import datetime, timedelta
|
6 |
+
import plotly.express as px
|
7 |
|
8 |
api_key = os.getenv("CEREBRAS_API_KEY")
|
9 |
url = "https://api.cerebras.ai/v1/chat/completions"
|
|
|
18 |
2025-04-12 10:03 UTC | 40.9N, 74.2W | Frequency: 14.6 GHz | Signal Strength: 90% | Message: Emergency: Low battery alert.
|
19 |
"""
|
20 |
|
|
|
21 |
LOG_HISTORY = []
|
22 |
|
23 |
def generate_random_log():
|
|
|
42 |
|
43 |
def analyze_log(log_text):
|
44 |
if not log_text.strip():
|
45 |
+
return "Error: Please enter a log.", None, None
|
46 |
LOG_HISTORY.append(log_text)
|
47 |
data = {
|
48 |
"model": "llama-4-scout-17b-16e-instruct",
|
|
|
58 |
try:
|
59 |
response = requests.post(url, json=data, headers=headers)
|
60 |
summary = response.json()["choices"][0]["message"]["content"]
|
|
|
61 |
html = "<div style='font-family:Arial;'><h3>Analysis Summary</h3><ul>"
|
62 |
for line in summary.split("\n"):
|
63 |
if "Issues:" in line:
|
|
|
69 |
elif line.strip():
|
70 |
html += f"<li>{line.strip()}</li>"
|
71 |
html += "</ul></div>"
|
72 |
+
# Extract signal strengths for plot
|
73 |
+
signals = [int(s.split("%")[0]) for s in log_text.split("\n") if "Signal Strength" in s]
|
74 |
+
times = [line.split(" | ")[0] for line in log_text.split("\n") if "Signal Strength" in s]
|
75 |
+
fig = px.line(x=times, y=signals, labels={"x": "Time", "y": "Signal Strength (%)"}, title="Signal Strength Trend")
|
76 |
+
return summary, html, fig
|
77 |
except Exception as e:
|
78 |
+
return f"Error: API call failed - {str(e)}", None, None
|
79 |
|
80 |
def generate_alert(log_text):
|
81 |
if not log_text.strip():
|
|
|
110 |
"content": "Compare these two satellite radio logs and summarize trends in bullet points (e.g., signal strength changes, frequency issues, new emergencies):\n" + compare_text
|
111 |
}
|
112 |
],
|
113 |
+
"max_completion_tokens": 300, # Increased
|
114 |
"temperature": 0.5
|
115 |
}
|
116 |
try:
|
|
|
133 |
|
134 |
with gr.Blocks(theme="huggingface/dark") as interface:
|
135 |
gr.Markdown("# Satellite Signal Log Analyzer")
|
136 |
+
gr.Markdown("Analyze satellite radio logs for issues, alerts, trends, and signal visuals using Llama 4 and Cerebras.")
|
137 |
log_input = gr.Textbox(lines=5, label="Satellite Radio Log")
|
138 |
with gr.Row():
|
139 |
sample_button = gr.Button("Load Sample Log")
|
|
|
144 |
alert_button = gr.Button("Generate Alert")
|
145 |
compare_button = gr.Button("Compare Last Two Logs")
|
146 |
output = gr.HTML(label="Analysis Summary")
|
147 |
+
plot_output = gr.Plot(label="Signal Strength Trend")
|
148 |
alert_output = gr.HTML(label="Satellite Alert")
|
149 |
compare_output = gr.HTML(label="Log Comparison")
|
150 |
sample_button.click(fn=load_sample_log, outputs=log_input)
|
151 |
random_button.click(fn=generate_random_log, outputs=log_input)
|
152 |
clear_button.click(fn=clear_log, outputs=log_input)
|
153 |
+
analyze_button.click(fn=analyze_log, inputs=log_input, outputs=[output, output, plot_output])
|
154 |
alert_button.click(fn=generate_alert, inputs=log_input, outputs=alert_output)
|
155 |
compare_button.click(fn=compare_logs, outputs=[compare_output, compare_output])
|
156 |
|