gyanbardhan123 commited on
Commit
e2ab02a
·
verified ·
1 Parent(s): acd90a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -71
app.py CHANGED
@@ -1,71 +1,71 @@
1
- #import gradio as gr
2
- #import tensorflow as tf
3
- #from transformers import TFDistilBertForSequenceClassification, DistilBertTokenizer
4
- #
5
- ## Load model and tokenizer
6
- #model_save_path = "saved_model" # replace with the actual path
7
- #model = TFDistilBertForSequenceClassification.from_pretrained(model_save_path)
8
- #tokenizer = DistilBertTokenizer.from_pretrained(model_save_path)
9
- #
10
- #def predict(question1, question2):
11
- # inputs = tokenizer(
12
- # [question1], [question2],
13
- # return_tensors='tf',
14
- # truncation=True,
15
- # padding=True,
16
- # max_length=50
17
- # )
18
- # outputs = model(inputs)
19
- # logits = outputs.logits
20
- # probabilities = tf.nn.softmax(logits, axis=-1)
21
- # prediction = tf.argmax(probabilities, axis=1).numpy()[0]
22
- # prob = probabilities.numpy()[0]
23
- # return f"{'Duplicate' if prediction == 1 else 'Not Duplicate'} (Probability: {prob})"
24
- #
25
- ## Gradio interface
26
- #interface = gr.Interface(
27
- # fn=predict,
28
- # inputs=["text", "text"],
29
- # outputs="text",
30
- # title="Duplicate Question Detection",
31
- # description="Enter two questions to check if they are duplicates."
32
- #)
33
- #
34
- #interface.launch()
35
-
36
- import streamlit as st
37
- import tensorflow as tf
38
- from transformers import TFDistilBertForSequenceClassification, DistilBertTokenizer
39
-
40
- # Load model and tokenizer
41
- model_save_path = "./saved_model" # replace with the actual path
42
- model = TFDistilBertForSequenceClassification.from_pretrained(model_save_path)
43
- tokenizer = DistilBertTokenizer.from_pretrained(model_save_path)
44
-
45
- # Streamlit app
46
- st.title("Duplicate Question Detection")
47
-
48
- question1 = st.text_input("Enter the first question:")
49
- question2 = st.text_input("Enter the second question:")
50
-
51
- if st.button("Predict"):
52
- if question1 and question2:
53
- inputs = tokenizer(
54
- [question1], [question2],
55
- return_tensors='tf',
56
- truncation=True,
57
- padding=True,
58
- max_length=50
59
- )
60
- outputs = model(inputs)
61
- logits = outputs.logits
62
- probabilities = tf.nn.softmax(logits, axis=-1)
63
- prediction = tf.argmax(probabilities, axis=1).numpy()[0] # 0 or 1
64
- prob = probabilities.numpy()[0]
65
-
66
- st.write(f"Prediction: {'Duplicate' if prediction == 1 else 'Not Duplicate'}")
67
- st.write(f"Probability: {prob}")
68
- else:
69
- st.write("Please enter both questions.")
70
-
71
-
 
1
+ #import gradio as gr
2
+ #import tensorflow as tf
3
+ #from transformers import TFDistilBertForSequenceClassification, DistilBertTokenizer
4
+ #
5
+ ## Load model and tokenizer
6
+ #model_save_path = "saved_model" # replace with the actual path
7
+ #model = TFDistilBertForSequenceClassification.from_pretrained(model_save_path)
8
+ #tokenizer = DistilBertTokenizer.from_pretrained(model_save_path)
9
+ #
10
+ #def predict(question1, question2):
11
+ # inputs = tokenizer(
12
+ # [question1], [question2],
13
+ # return_tensors='tf',
14
+ # truncation=True,
15
+ # padding=True,
16
+ # max_length=50
17
+ # )
18
+ # outputs = model(inputs)
19
+ # logits = outputs.logits
20
+ # probabilities = tf.nn.softmax(logits, axis=-1)
21
+ # prediction = tf.argmax(probabilities, axis=1).numpy()[0]
22
+ # prob = probabilities.numpy()[0]
23
+ # return f"{'Duplicate' if prediction == 1 else 'Not Duplicate'} (Probability: {prob})"
24
+ #
25
+ ## Gradio interface
26
+ #interface = gr.Interface(
27
+ # fn=predict,
28
+ # inputs=["text", "text"],
29
+ # outputs="text",
30
+ # title="Duplicate Question Detection",
31
+ # description="Enter two questions to check if they are duplicates."
32
+ #)
33
+ #
34
+ #interface.launch()
35
+
36
+ import streamlit as st
37
+ import tensorflow as tf
38
+ from transformers import TFDistilBertForSequenceClassification, DistilBertTokenizer
39
+
40
+ # Load model and tokenizer
41
+ model_save_path = "./saved_model" # replace with the actual path
42
+ model = TFDistilBertForSequenceClassification.from_pretrained(model_save_path)
43
+ tokenizer = DistilBertTokenizer.from_pretrained(model_save_path)
44
+
45
+ # Streamlit app
46
+ st.title("Duplicate Question Detection")
47
+
48
+ question1 = st.text_input("Enter the first question:")
49
+ question2 = st.text_input("Enter the second question:")
50
+
51
+ if st.button("Predict"):
52
+ if question1 and question2:
53
+ inputs = tokenizer(
54
+ [question1], [question2],
55
+ return_tensors='tf',
56
+ truncation=True,
57
+ padding=True,
58
+ max_length=50
59
+ )
60
+ outputs = model(inputs)
61
+ logits = outputs.logits
62
+ probabilities = tf.nn.softmax(logits, axis=-1)
63
+ prediction = tf.argmax(probabilities, axis=1).numpy()[0] # 0 or 1
64
+ prob = probabilities.numpy()[0]
65
+
66
+ st.success(f"Prediction: {'Duplicate' if prediction == 1 else 'Not Duplicate'}")
67
+ st.success(f"Probability: Not Duplicate {prob[0]} Duplicate {prob[1]}")
68
+ else:
69
+ st.write("Please enter both questions.")
70
+
71
+