fahmiaziz98 commited on
Commit
43148dc
·
1 Parent(s): 6753f91

first commit

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -41,10 +41,13 @@ if model_choice not in st.session_state.downloaded_models:
41
  if model_choice == "TinyBert Sentiment Analysis":
42
  text = st.text_area("Enter Text:", "This movie was horrible, the plot was really boring. acting was okay")
43
  predict = st.button("Predict Sentiment")
 
 
 
 
 
44
 
45
- classifier = pipeline("text-classification", model=local_path, device=device)
46
-
47
- if predict:
48
  with st.spinner("Predicting..."):
49
  output = classifier(text)
50
  st.write(output)
@@ -53,10 +56,13 @@ if model_choice == "TinyBert Sentiment Analysis":
53
  if model_choice == "TinyBert Disaster Classification":
54
  text = st.text_area("Enter Text:", "There is a fire in the building")
55
  predict = st.button("Predict Sentiment")
 
 
 
 
 
56
 
57
- classifier = pipeline("text-classification", model=local_path, device=device)
58
-
59
- if predict:
60
  with st.spinner("Predicting..."):
61
  output = classifier(text)
62
  st.write(output)
@@ -68,7 +74,7 @@ if model_choice == "VIT Pose Classification":
68
 
69
  if uploaded_file is not None:
70
  image = Image.open(uploaded_file)
71
- st.image(image, caption="Your Image", use_column_width=True)
72
 
73
  image_processor = AutoImageProcessor.from_pretrained(local_path, use_fast=True)
74
  pipe = pipeline('image-classification', model=local_path, image_processor=image_processor, device=device)
 
41
  if model_choice == "TinyBert Sentiment Analysis":
42
  text = st.text_area("Enter Text:", "This movie was horrible, the plot was really boring. acting was okay")
43
  predict = st.button("Predict Sentiment")
44
+ try:
45
+ classifier = pipeline("text-classification", model=local_path, device=device)
46
+ except OSError:
47
+ st.error("❌ Model not found. Please download the model first.")
48
+ classifier = None
49
 
50
+ if predict and classifier:
 
 
51
  with st.spinner("Predicting..."):
52
  output = classifier(text)
53
  st.write(output)
 
56
  if model_choice == "TinyBert Disaster Classification":
57
  text = st.text_area("Enter Text:", "There is a fire in the building")
58
  predict = st.button("Predict Sentiment")
59
+ try:
60
+ classifier = pipeline("text-classification", model=local_path, device=device)
61
+ except OSError:
62
+ st.error("❌ Model not found. Please download the model first.")
63
+ classifier = None
64
 
65
+ if predict and classifier:
 
 
66
  with st.spinner("Predicting..."):
67
  output = classifier(text)
68
  st.write(output)
 
74
 
75
  if uploaded_file is not None:
76
  image = Image.open(uploaded_file)
77
+ st.image(image, caption="Your Image", width=300)
78
 
79
  image_processor = AutoImageProcessor.from_pretrained(local_path, use_fast=True)
80
  pipe = pipeline('image-classification', model=local_path, image_processor=image_processor, device=device)