Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,31 +8,34 @@ from nltk.stem import WordNetLemmatizer
|
|
| 8 |
from transformers import pipeline
|
| 9 |
from PIL import Image
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
if "device_type" not in st.session_state:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
st.
|
| 24 |
-
|
| 25 |
-
# Wait for response from JavaScript
|
| 26 |
-
device_type = st.selectbox("Select your device type", ["Mobile", "PC"])
|
| 27 |
-
st.session_state.device_type = device_type
|
| 28 |
-
|
| 29 |
-
# Set the layout only ONCE at the start
|
| 30 |
-
if get_device_type() == "Mobile":
|
| 31 |
-
st.set_page_config(page_title="News Classifier", page_icon="π°", layout="centered")
|
| 32 |
else:
|
| 33 |
-
st.
|
| 34 |
|
| 35 |
-
#
|
| 36 |
nltk.download('stopwords')
|
| 37 |
nltk.download('wordnet')
|
| 38 |
nltk.download('omw-1.4')
|
|
|
|
| 8 |
from transformers import pipeline
|
| 9 |
from PIL import Image
|
| 10 |
|
| 11 |
+
# β
Set page config as the first Streamlit command (default to wide)
|
| 12 |
+
st.set_page_config(page_title="News Classifier", page_icon="π°", layout="wide")
|
| 13 |
+
|
| 14 |
+
# β
Use JavaScript to detect screen size and update session state
|
| 15 |
+
device_type_script = """
|
| 16 |
+
<script>
|
| 17 |
+
let screen_width = window.innerWidth;
|
| 18 |
+
let device_type = screen_width < 768 ? "Mobile" : "PC";
|
| 19 |
+
let streamlitVar = window.parent;
|
| 20 |
+
streamlitVar.postMessage({device_type: device_type}, "*");
|
| 21 |
+
</script>
|
| 22 |
+
"""
|
| 23 |
+
st.markdown(device_type_script, unsafe_allow_html=True)
|
| 24 |
+
|
| 25 |
+
# β
Initialize session state
|
| 26 |
if "device_type" not in st.session_state:
|
| 27 |
+
st.session_state.device_type = "PC" # Default to PC
|
| 28 |
+
|
| 29 |
+
# β
Allow user to manually select device type (Optional)
|
| 30 |
+
st.session_state.device_type = st.radio("Select your device type", ["Mobile", "PC"], index=0 if st.session_state.device_type == "PC" else 1)
|
| 31 |
+
|
| 32 |
+
# β
Apply UI adjustments based on device type
|
| 33 |
+
if st.session_state.device_type == "Mobile":
|
| 34 |
+
st.write("π± Mobile Mode Activated (UI adjusted)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
else:
|
| 36 |
+
st.write("π» PC Mode Activated (Full-width UI)")
|
| 37 |
|
| 38 |
+
# β
Continue with the rest of the app
|
| 39 |
nltk.download('stopwords')
|
| 40 |
nltk.download('wordnet')
|
| 41 |
nltk.download('omw-1.4')
|