Ashendilantha commited on
Commit
9b6c6b1
·
verified ·
1 Parent(s): 9603614

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -8,14 +8,25 @@ from nltk.stem import WordNetLemmatizer
8
  from transformers import pipeline
9
  from PIL import Image
10
 
11
- # Set page config FIRST
12
- device_type = st.radio("Are you using a mobile device or a PC?", ["Mobile", "PC"])
13
- if device_type == "Mobile":
14
- st.set_page_config(page_title="News Classifier", page_icon="📰", layout="centered")
15
- else:
16
- st.set_page_config(page_title="News Classifier", page_icon="📰", layout="wide")
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- # Now the rest of the imports and app logic continue
19
  nltk.download('stopwords')
20
  nltk.download('wordnet')
21
  nltk.download('omw-1.4')
 
8
  from transformers import pipeline
9
  from PIL import Image
10
 
11
+ # Move set_page_config to the first line with a default layout
12
+ st.set_page_config(page_title="News Classifier", page_icon="📰", layout="wide")
13
+
14
+ # Function to detect device type
15
+ def detect_device():
16
+ user_agent = st.experimental_get_query_params().get("user_agent", [""])[0]
17
+ if "mobi" in user_agent.lower():
18
+ return "Mobile"
19
+ return "PC"
20
+
21
+ # Ask user for device preference (only if not already set)
22
+ if "device_type" not in st.session_state:
23
+ st.session_state.device_type = st.radio("Are you using a mobile device or a PC?", ["Mobile", "PC"])
24
+
25
+ # Adjust layout based on user selection
26
+ if st.session_state.device_type == "Mobile":
27
+ st.set_page_config(layout="centered") # Not needed if already set, but here for clarity
28
 
29
+ # Continue with the rest of the code
30
  nltk.download('stopwords')
31
  nltk.download('wordnet')
32
  nltk.download('omw-1.4')