Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
import os
|
|
|
|
|
4 |
|
5 |
api_key = os.getenv("CEREBRAS_API_KEY")
|
6 |
url = "https://api.cerebras.ai/v1/chat/completions"
|
@@ -15,6 +17,25 @@ SAMPLE_LOG = """
|
|
15 |
2025-04-12 10:03 UTC | 40.9N, 74.2W | Frequency: 14.6 GHz | Signal Strength: 90% | Message: Emergency: Low battery alert.
|
16 |
"""
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def analyze_log(log_text):
|
19 |
if not log_text.strip():
|
20 |
return "Error: Please enter a log."
|
@@ -26,7 +47,7 @@ def analyze_log(log_text):
|
|
26 |
"content": "Analyze this satellite radio log and summarize in bullet points. Ensure frequencies are included in issues (if relevant) and key details:\n- Issues (e.g., low signal, noise, interference with frequency)\n- High-priority messages (e.g., emergencies)\n- Key details (coordinates, times, frequencies, signal strengths)\nLog:\n" + log_text
|
27 |
}
|
28 |
],
|
29 |
-
"max_completion_tokens": 400,
|
30 |
"temperature": 0.5
|
31 |
}
|
32 |
try:
|
@@ -40,12 +61,15 @@ def load_sample_log():
|
|
40 |
|
41 |
with gr.Blocks() as interface:
|
42 |
gr.Markdown("# Satellite Signal Log Analyzer")
|
43 |
-
gr.Markdown("Enter a satellite radio log to detect issues, priorities, and details (including frequencies) using Llama 4 and Cerebras.")
|
44 |
log_input = gr.Textbox(lines=5, label="Satellite Radio Log")
|
45 |
-
|
|
|
|
|
46 |
output = gr.Textbox(label="Analysis Summary")
|
47 |
analyze_button = gr.Button("Analyze")
|
48 |
sample_button.click(fn=load_sample_log, outputs=log_input)
|
|
|
49 |
analyze_button.click(fn=analyze_log, inputs=log_input, outputs=output)
|
50 |
|
51 |
interface.launch()
|
|
|
1 |
import requests
|
2 |
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 |
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 |
+
def generate_random_log():
|
21 |
+
base_time = datetime(2025, 4, 12, 10, 0)
|
22 |
+
entries = []
|
23 |
+
for i in range(3):
|
24 |
+
time = (base_time + timedelta(minutes=i)).strftime("%Y-%m-%d %H:%M UTC")
|
25 |
+
lat = round(random.uniform(40.0, 41.0), 1)
|
26 |
+
lon = round(random.uniform(73.0, 74.0), 1)
|
27 |
+
freq = round(random.uniform(14.0, 15.0), 1)
|
28 |
+
signal = random.randint(50, 100)
|
29 |
+
messages = [
|
30 |
+
"Routine check, systems OK.",
|
31 |
+
"Noise detected, possible interference.",
|
32 |
+
"Emergency: Low battery alert.",
|
33 |
+
"Signal stable, no issues."
|
34 |
+
]
|
35 |
+
message = random.choice(messages)
|
36 |
+
entries.append(f"{time} | {lat}N, {lon}W | Frequency: {freq} GHz | Signal Strength: {signal}% | Message: {message}")
|
37 |
+
return "\n".join(entries)
|
38 |
+
|
39 |
def analyze_log(log_text):
|
40 |
if not log_text.strip():
|
41 |
return "Error: Please enter a log."
|
|
|
47 |
"content": "Analyze this satellite radio log and summarize in bullet points. Ensure frequencies are included in issues (if relevant) and key details:\n- Issues (e.g., low signal, noise, interference with frequency)\n- High-priority messages (e.g., emergencies)\n- Key details (coordinates, times, frequencies, signal strengths)\nLog:\n" + log_text
|
48 |
}
|
49 |
],
|
50 |
+
"max_completion_tokens": 400,
|
51 |
"temperature": 0.5
|
52 |
}
|
53 |
try:
|
|
|
61 |
|
62 |
with gr.Blocks() as interface:
|
63 |
gr.Markdown("# Satellite Signal Log Analyzer")
|
64 |
+
gr.Markdown("Enter a satellite radio log or generate one to detect issues, priorities, and details (including frequencies) using Llama 4 and Cerebras.")
|
65 |
log_input = gr.Textbox(lines=5, label="Satellite Radio Log")
|
66 |
+
with gr.Row():
|
67 |
+
sample_button = gr.Button("Load Sample Log")
|
68 |
+
random_button = gr.Button("Generate Random Log")
|
69 |
output = gr.Textbox(label="Analysis Summary")
|
70 |
analyze_button = gr.Button("Analyze")
|
71 |
sample_button.click(fn=load_sample_log, outputs=log_input)
|
72 |
+
random_button.click(fn=generate_random_log, outputs=log_input)
|
73 |
analyze_button.click(fn=analyze_log, inputs=log_input, outputs=output)
|
74 |
|
75 |
interface.launch()
|