workbykait commited on
Commit
a89d904
·
verified ·
1 Parent(s): f8cbedd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"
7
+ headers = {
8
+ "Authorization": f"Bearer {api_key}",
9
+ "Content-Type": "application/json"
10
+ }
11
+
12
+ def analyze_log(log_text):
13
+ if not log_text.strip():
14
+ return "Error: Please enter a log."
15
+ data = {
16
+ "model": "llama-4-scout-17b-16e-instruct",
17
+ "messages": [
18
+ {
19
+ "role": "user",
20
+ "content": "Analyze this satellite radio log and summarize in bullet points:\n- Issues (e.g., low signal, noise)\n- High-priority messages (e.g., emergencies)\n- Key details (e.g., coordinates, times)\nLog:\n" + log_text
21
+ }
22
+ ],
23
+ "max_completion_tokens": 200, # Increased again
24
+ "temperature": 0.5
25
+ }
26
+ try:
27
+ response = requests.post(url, json=data, headers=headers)
28
+ return response.json()["choices"][0]["message"]["content"]
29
+ except Exception as e:
30
+ return f"Error: API call failed - {str(e)}"
31
+
32
+ interface = gr.Interface(
33
+ fn=analyze_log,
34
+ inputs=gr.Textbox(lines=5, label="Paste Satellite Radio Log"),
35
+ outputs=gr.Textbox(label="Analysis Summary"),
36
+ title="Satellite Signal Log Analyzer",
37
+ description="Enter a satellite radio log to detect issues and priorities using Llama 4 and Cerebras."
38
+ )
39
+ interface.launch()