bimal590 commited on
Commit
aab509b
·
1 Parent(s): 7285f10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -1,23 +1,25 @@
1
-
2
  import gradio as gr
3
  import tensorflow as tf
4
  import tensorflow_hub as hub
 
5
 
 
 
6
 
7
- # def is_cat(x) : return x[0].isupper()
8
-
9
- options = tf.saved_model.LoadOptions(experimental_io_device='/job:localhost')
10
- learn = tf.keras.models.load_model('my_model.h5', custom_objects={'KerasLayer': hub.KerasLayer}, options=options)
11
-
12
-
13
- categories = ('Spam', 'Not spam')
14
 
15
  def classify_review(review):
16
- pred,idx,probs = learn.predict(review)
17
- return dict(zip(categories, map(float, probs)))
18
-
19
- review = gr.inputs.Textbox()
 
 
 
 
 
 
20
  label = gr.outputs.Label()
 
21
  examples = [
22
  """Congratulations! You have been selected as the lucky winner of our exclusive offer.
23
  Get a chance to win a free vacation package by participating in our online survey.
@@ -33,4 +35,6 @@ examples = [
33
  ]
34
 
35
  intf = gr.Interface(fn=classify_review, inputs=review, outputs=label, examples=examples)
36
- intf.launch(inline=False)
 
 
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import tensorflow_hub as hub
4
+ import tensorflow_text as text
5
 
6
+ new_model = tf.keras.models.load_model('my_model.h5', custom_objects={'KerasLayer': hub.KerasLayer})
7
+ categories = ('Spam', 'Not Spam')
8
 
 
 
 
 
 
 
 
9
 
10
  def classify_review(review):
11
+ if review.strip() != "":
12
+ prob = new_model.predict([review])
13
+ spam_probability = float(prob[0][0])
14
+ output_label = f"Probability of being spam: {spam_probability}"
15
+ return output_label
16
+ else:
17
+ return "Enter a review first"
18
+
19
+
20
+ review = gr.inputs.Textbox(label="Review")
21
  label = gr.outputs.Label()
22
+
23
  examples = [
24
  """Congratulations! You have been selected as the lucky winner of our exclusive offer.
25
  Get a chance to win a free vacation package by participating in our online survey.
 
35
  ]
36
 
37
  intf = gr.Interface(fn=classify_review, inputs=review, outputs=label, examples=examples)
38
+
39
+ if __name__ == "__main__":
40
+ intf.launch(inline=False, share=True)