File size: 1,708 Bytes
7a75bfa
 
765c1a5
aab509b
765c1a5
aab509b
 
7a75bfa
 
 
aab509b
 
 
 
 
 
 
 
 
 
7a75bfa
aab509b
7a75bfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aab509b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_text as text

new_model = tf.keras.models.load_model('my_model.h5', custom_objects={'KerasLayer': hub.KerasLayer})
categories = ('Spam', 'Not Spam')


def classify_review(review):
    if review.strip() != "":
        prob = new_model.predict([review])
        spam_probability = float(prob[0][0])
        output_label = f"Probability of being spam: {spam_probability}"
        return output_label
    else:
        return "Enter a review first"
    

review = gr.inputs.Textbox(label="Review")
label = gr.outputs.Label()

examples = [
    """Congratulations! You have been selected as the lucky winner of our exclusive offer. 
    Get a chance to win a free vacation package by participating in our online survey. 
    Simply click the link below and provide your feedback to qualify for the prize.
    Hurry, this offer is available for a limited time only. Don't miss out on this amazing opportunity!""",

    """Hi [Recipient],I hope this email finds you well. I wanted to inform you about the upcoming
    team-building event scheduled for next week. We have organized a fun-filled day of activities
    and games to strengthen team bonds and foster collaboration.Please block your calendar for the
    event on [Date] from [Time]. It will take place at [Location]. Lunch and snacks will be provided,
    so you can focus on enjoying the day with your colleagues.We look forward to seeing you there and
    creating memorable experiences together."""
]

intf = gr.Interface(fn=classify_review, inputs=review, outputs=label, examples=examples)

if __name__ == "__main__":
    intf.launch(inline=False, share=True)