pravjet commited on
Commit
0afb2cd
·
verified ·
1 Parent(s): 927ec61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -1,12 +1,25 @@
1
- from flask import Flask, request, jsonify
2
  from transformers import pipeline
3
  from newspaper import Article
 
4
 
5
- app = Flask(__name__)
 
 
 
 
6
 
7
- # You can change the model here for better accuracy
8
  model = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
9
 
 
 
 
 
 
 
 
 
10
  @app.route("/analyze", methods=["POST"])
11
  def analyze():
12
  data = request.get_json() or {}
@@ -26,7 +39,6 @@ def analyze():
26
  return jsonify({"error": "No text provided"}), 400
27
 
28
  try:
29
- # Optionally, preprocess text here for better accuracy
30
  result = model(text)[0]
31
  label = result["label"]
32
  score = result["score"]
 
1
+ from flask import Flask, request, jsonify, send_from_directory
2
  from transformers import pipeline
3
  from newspaper import Article
4
+ import os
5
 
6
+ app = Flask(
7
+ __name__,
8
+ static_folder="frontend/static",
9
+ template_folder="frontend/templates"
10
+ )
11
 
12
+ # Load the smallest model for resource efficiency
13
  model = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
14
 
15
+ @app.route("/")
16
+ def index():
17
+ return send_from_directory("frontend/templates", "index.html")
18
+
19
+ @app.route("/static/<path:path>")
20
+ def static_files(path):
21
+ return send_from_directory("frontend/static", path)
22
+
23
  @app.route("/analyze", methods=["POST"])
24
  def analyze():
25
  data = request.get_json() or {}
 
39
  return jsonify({"error": "No text provided"}), 400
40
 
41
  try:
 
42
  result = model(text)[0]
43
  label = result["label"]
44
  score = result["score"]