Spaces:
Sleeping
Sleeping
up
Browse files- app.py +31 -5
- requirements.txt +3 -0
- try_model_webui.py +0 -35
app.py
CHANGED
@@ -1,7 +1,33 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request
|
2 |
+
import nltk
|
3 |
+
from nltk.corpus import stopwords
|
4 |
+
import joblib
|
5 |
|
6 |
+
app = Flask(__name__)
|
|
|
7 |
|
8 |
+
# Load the trained model and vectorizer outside the routes for better performance
|
9 |
+
loaded_classifier = joblib.load("is_this_bible_model.pkl")
|
10 |
+
vectorizer = joblib.load("is_this_bible_vectorizer.pkl")
|
11 |
+
|
12 |
+
def parse_text(new_text):
|
13 |
+
new_text_tfidf = vectorizer.transform([new_text])
|
14 |
+
prediction = loaded_classifier.predict(new_text_tfidf)
|
15 |
+
probabilities = loaded_classifier.predict_proba(new_text_tfidf)
|
16 |
+
confidence_score = probabilities[0, 1]
|
17 |
+
return 'תנ"ך' if prediction[0] == 1 else 'אחר', confidence_score
|
18 |
+
|
19 |
+
@app.route('/', methods=['GET', 'POST'])
|
20 |
+
def index():
|
21 |
+
prediction = None
|
22 |
+
confidence_score = None
|
23 |
+
new_text = None
|
24 |
+
|
25 |
+
if request.method == 'POST':
|
26 |
+
new_text = request.form['new_text']
|
27 |
+
if new_text:
|
28 |
+
prediction, confidence_score = parse_text(new_text)
|
29 |
+
return render_template('index.html', new_text=new_text, prediction=prediction, confidence_score=confidence_score)
|
30 |
+
|
31 |
+
|
32 |
+
if __name__ == '__main__':
|
33 |
+
app.run(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Flask
|
2 |
+
nltk
|
3 |
+
joblib
|
try_model_webui.py
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
from flask import Flask, render_template, request
|
2 |
-
import webbrowser
|
3 |
-
import nltk
|
4 |
-
from nltk.corpus import stopwords
|
5 |
-
import joblib
|
6 |
-
|
7 |
-
app = Flask(__name__)
|
8 |
-
|
9 |
-
# Load the trained model and vectorizer outside the routes for better performance
|
10 |
-
loaded_classifier = joblib.load("is_this_bible_model.pkl")
|
11 |
-
vectorizer = joblib.load("is_this_bible_vectorizer.pkl")
|
12 |
-
|
13 |
-
def parse_text(new_text):
|
14 |
-
new_text_tfidf = vectorizer.transform([new_text])
|
15 |
-
prediction = loaded_classifier.predict(new_text_tfidf)
|
16 |
-
probabilities = loaded_classifier.predict_proba(new_text_tfidf)
|
17 |
-
confidence_score = probabilities[0, 1]
|
18 |
-
return 'תנ"ך' if prediction[0] == 1 else 'אחר', confidence_score
|
19 |
-
|
20 |
-
@app.route('/', methods=['GET', 'POST'])
|
21 |
-
def index():
|
22 |
-
prediction = None
|
23 |
-
confidence_score = None
|
24 |
-
new_text = None
|
25 |
-
|
26 |
-
if request.method == 'POST':
|
27 |
-
new_text = request.form['new_text']
|
28 |
-
if new_text:
|
29 |
-
prediction, confidence_score = parse_text(new_text)
|
30 |
-
return render_template('index.html', new_text=new_text, prediction=prediction, confidence_score=confidence_score)
|
31 |
-
|
32 |
-
|
33 |
-
if __name__ == '__main__':
|
34 |
-
webbrowser.open('http://127.0.0.1:5000/')
|
35 |
-
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|