ZodiUOA commited on
Commit
459dcd5
·
1 Parent(s): 6160ac9

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. main.py +43 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["gunicorn", "-b","0.0.0.0:7860" "main:app"]
main.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask,render_template,url_for,request
2
+ from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification
3
+
4
+ # name = 'Giyaseddin/distilbert-base-cased-finetuned-fake-and-real-news-dataset'
5
+
6
+ # tokenizer = AutoTokenizer.from_pretrained(name)
7
+ # model = AutoModelForSequenceClassification.from_pretrained('/Users/jorgemeneumoreno/Desktop/FakeNewsClassifier/model', max_position_embeddings=512)
8
+
9
+ #pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer)
10
+ # Use a pipeline as a high-level helper
11
+ from transformers import pipeline
12
+ pipe = pipeline("text-classification", model="Giyaseddin/distilbert-base-cased-finetuned-fake-and-real-news-dataset")
13
+
14
+ # Load model directly
15
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
16
+ tokenizer = AutoTokenizer.from_pretrained("Giyaseddin/distilbert-base-cased-finetuned-fake-and-real-news-dataset")
17
+ model = AutoModelForSequenceClassification.from_pretrained('model', max_position_embeddings=512)
18
+
19
+ application = app = Flask(__name__)
20
+
21
+ @application.route('/')
22
+ def home():
23
+ return render_template('home.html')
24
+ @application.route('/predict',methods=['POST'])
25
+
26
+ def predict():
27
+ if request.method == 'POST':
28
+ input_message = request.form['message']
29
+ if len(input_message)>=511:
30
+ input_message= input_message[0:512]
31
+ if input_message.strip() == "":
32
+ result="Please enter the body of an article"
33
+ my_input = [input_message]
34
+ preds = pipe(my_input, return_all_scores=True)
35
+ output_dict = {'Real': preds[0][0]['score'], 'Fake': preds[0][1]['score']}
36
+ print(output_dict)
37
+ print(list(output_dict.keys()), list(output_dict.values()))
38
+ props = [(round(float(v)*100, 2)) for v in list(output_dict.values())]
39
+ print(props)
40
+ return render_template('result.html', mess = input_message, classes = list(output_dict.keys()), props=props)
41
+
42
+ if __name__ == '__main__':
43
+ app.run(port=5000,debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask
2
+ transformers
3
+ gunicorn