Spaces:
Sleeping
Sleeping
add: html page
Browse files- main.py +16 -13
- static/css/style.css +6 -0
- templates/index.html +26 -0
main.py
CHANGED
|
@@ -5,8 +5,11 @@ app = Flask(__name__)
|
|
| 5 |
|
| 6 |
@app.route('/')
|
| 7 |
def index():
|
| 8 |
-
|
|
|
|
| 9 |
|
|
|
|
|
|
|
| 10 |
import torch
|
| 11 |
from transformers import pipeline
|
| 12 |
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
|
@@ -19,19 +22,19 @@ from PIL import Image
|
|
| 19 |
classifier_doctype_processor = DonutProcessor.from_pretrained("calumpianojericho/donutclassifier_acctdocs_by_doctype")
|
| 20 |
classifier_doctype_model = VisionEncoderDecoderModel.from_pretrained("calumpianojericho/donutclassifier_acctdocs_by_doctype")
|
| 21 |
|
| 22 |
-
# Load the sentiment analysis model
|
| 23 |
-
sentiment_analysis = pipeline("sentiment-analysis")
|
| 24 |
|
| 25 |
-
@app.route("/analyze", methods=["POST"])
|
| 26 |
-
def analyze_sentiment():
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 5 |
|
| 6 |
@app.route('/')
|
| 7 |
def index():
|
| 8 |
+
sentiment_analysis = pipeline("sentiment-analysis")
|
| 9 |
+
result = sentiment_analysis("I absolutely love this product!")
|
| 10 |
|
| 11 |
+
return render_template('index.html', res=jsonify({"sentiment": result[0]["label"], "score": result[0]["score"]}))
|
| 12 |
+
|
| 13 |
import torch
|
| 14 |
from transformers import pipeline
|
| 15 |
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
|
|
|
| 22 |
classifier_doctype_processor = DonutProcessor.from_pretrained("calumpianojericho/donutclassifier_acctdocs_by_doctype")
|
| 23 |
classifier_doctype_model = VisionEncoderDecoderModel.from_pretrained("calumpianojericho/donutclassifier_acctdocs_by_doctype")
|
| 24 |
|
| 25 |
+
# # Load the sentiment analysis model
|
| 26 |
+
# sentiment_analysis = pipeline("sentiment-analysis")
|
| 27 |
|
| 28 |
+
# @app.route("/analyze", methods=["POST"])
|
| 29 |
+
# def analyze_sentiment():
|
| 30 |
+
# try:
|
| 31 |
+
# data = request.json
|
| 32 |
+
# text = data["text"]
|
| 33 |
|
| 34 |
+
# # Perform sentiment analysis
|
| 35 |
+
# result = sentiment_analysis(text)
|
| 36 |
|
| 37 |
+
# return jsonify({"sentiment": result[0]["label"], "score": result[0]["score"]})
|
| 38 |
|
| 39 |
+
# except Exception as e:
|
| 40 |
+
# return jsonify({"error": str(e)}), 500
|
static/css/style.css
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
h1 {
|
| 2 |
+
border: 2px #eee solid;
|
| 3 |
+
color: brown;
|
| 4 |
+
text-align: center;
|
| 5 |
+
padding: 10px;
|
| 6 |
+
}
|
templates/index.html
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
| 6 |
+
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/style.css') }}">
|
| 7 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 8 |
+
<title>Document</title>
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<h1>Welcome!</h1>
|
| 12 |
+
<ul>
|
| 13 |
+
{% for key, value in res.items() recursive %}
|
| 14 |
+
<li>
|
| 15 |
+
{% if value is string %}
|
| 16 |
+
<a href="{{ value }}">{{ key }}</a>
|
| 17 |
+
{% else %}
|
| 18 |
+
{{ key }}
|
| 19 |
+
<ul>{{ loop(value.items()) }}</ul>
|
| 20 |
+
{% endif %}
|
| 21 |
+
</li>
|
| 22 |
+
{% endfor %}
|
| 23 |
+
</ul>
|
| 24 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
| 25 |
+
</body>
|
| 26 |
+
</html>
|