Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,29 @@
|
|
| 1 |
-
import os
|
| 2 |
import streamlit as st
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 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}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|