waqasbm commited on
Commit
61857b5
·
verified ·
1 Parent(s): 613f132

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -56
app.py CHANGED
@@ -1,57 +1,29 @@
1
- import os
2
  import streamlit as st
3
- import requests
4
-
5
- # Load GROQ API key securely
6
- GROQ_API_KEY = os.getenv("speedtest")
7
-
8
- # GROQ Chat endpoint
9
- GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
10
-
11
- def analyze_speed_with_groq(download, upload, ping):
12
- headers = {
13
- "Authorization": f"Bearer {GROQ_API_KEY}",
14
- "Content-Type": "application/json"
15
- }
16
-
17
- prompt = (
18
- f"My network speed test shows:\n"
19
- f"Download Speed: {download} Mbps\n"
20
- f"Upload Speed: {upload} Mbps\n"
21
- f"Latency: {ping} ms\n\n"
22
- "Based on this, tell me what type of online activities my connection can handle (e.g., Zoom calls, gaming, 4K streaming, etc.)"
23
- )
24
-
25
- payload = {
26
- "model": "llama3-8b-8192",
27
- "messages": [{"role": "user", "content": prompt}]
28
- }
29
-
30
- response = requests.post(GROQ_API_URL, headers=headers, json=payload)
31
-
32
- if response.status_code == 200:
33
- return response.json()["choices"][0]["message"]["content"]
34
- else:
35
- return f"❌ GROQ API Error: {response.status_code} - {response.text}"
36
-
37
- # Streamlit App UI
38
- st.set_page_config(page_title="Network Speed Analysis", layout="centered")
39
- st.title("📶 Network Speed Insight with GROQ AI")
40
-
41
- with st.form("speed_input_form"):
42
- st.markdown("Simulate your speed test:")
43
- download = st.slider("Download Speed (Mbps)", 1, 1000, 100)
44
- upload = st.slider("Upload Speed (Mbps)", 1, 500, 50)
45
- ping = st.slider("Ping (ms)", 1, 500, 30)
46
- submitted = st.form_submit_button("🔍 Analyze with GROQ")
47
-
48
- if submitted:
49
- st.markdown("### 🧪 Speed Test Input")
50
- st.write(f"📡 **Download**: {download} Mbps")
51
- st.write(f"📤 **Upload**: {upload} Mbps")
52
- st.write(f"⏱️ **Ping**: {ping} ms")
53
-
54
- st.markdown("### 🧠 GROQ AI Suggests:")
55
- with st.spinner("Analyzing with LLM..."):
56
- result = analyze_speed_with_groq(download, upload, ping)
57
- st.success(result)
 
 
1
  import streamlit as st
2
+ import speedtest
3
+ import time
4
+
5
+ st.set_page_config(page_title="Speed Test App", layout="centered")
6
+ st.title("📶 Internet Speed Test")
7
+
8
+ if st.button("▶️ Start Speed Test"):
9
+ with st.spinner("Running test... please wait..."):
10
+ try:
11
+ stt = speedtest.Speedtest()
12
+ stt.get_best_server()
13
+
14
+ start = time.time()
15
+ download = stt.download()
16
+ upload = stt.upload()
17
+ end = time.time()
18
+
19
+ download_mbps = round(download / 1_000_000, 2)
20
+ upload_mbps = round(upload / 1_000_000, 2)
21
+ test_time_ms = round((end - start) * 1000, 2)
22
+
23
+ st.success("✅ Speed Test Complete!")
24
+ st.markdown(f"**📥 Download Speed:** `{download_mbps} Mbps`")
25
+ st.markdown(f"**📤 Upload Speed :** `{upload_mbps} Mbps`")
26
+ st.markdown(f"**⏱️ Test Time :** `{test_time_ms} ms`")
27
+
28
+ except Exception as e:
29
+ st.error(f"❌ Error running speed test: {e}")