Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,22 +8,31 @@ from nltk.stem import WordNetLemmatizer
|
|
| 8 |
from transformers import pipeline
|
| 9 |
from PIL import Image
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
st.
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
st.session_state.device_type = device_type
|
| 18 |
-
st.rerun() # Corrected method for refreshing the app
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
if
|
| 22 |
st.set_page_config(page_title="News Classifier", page_icon="📰", layout="centered")
|
| 23 |
else:
|
| 24 |
st.set_page_config(page_title="News Classifier", page_icon="📰", layout="wide")
|
| 25 |
|
| 26 |
-
# Now continue with the rest of
|
| 27 |
nltk.download('stopwords')
|
| 28 |
nltk.download('wordnet')
|
| 29 |
nltk.download('omw-1.4')
|
|
|
|
| 8 |
from transformers import pipeline
|
| 9 |
from PIL import Image
|
| 10 |
|
| 11 |
+
# JavaScript to detect screen width
|
| 12 |
+
def get_device_type():
|
| 13 |
+
return st.session_state.get("device_type", None)
|
| 14 |
|
| 15 |
+
if "device_type" not in st.session_state:
|
| 16 |
+
device_type_script = """
|
| 17 |
+
<script>
|
| 18 |
+
let screen_width = window.innerWidth;
|
| 19 |
+
let device_type = screen_width < 768 ? "Mobile" : "PC";
|
| 20 |
+
window.parent.postMessage(device_type, "*");
|
| 21 |
+
</script>
|
| 22 |
+
"""
|
| 23 |
+
st.markdown(device_type_script, unsafe_allow_html=True)
|
| 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.set_page_config(page_title="News Classifier", page_icon="📰", layout="wide")
|
| 34 |
|
| 35 |
+
# Now continue with the rest of the app
|
| 36 |
nltk.download('stopwords')
|
| 37 |
nltk.download('wordnet')
|
| 38 |
nltk.download('omw-1.4')
|