File size: 2,291 Bytes
88eb3b8
2166f46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88eb3b8
e19e130
af0a55c
 
 
 
 
 
 
aaeedf0
 
057478d
aaeedf0
 
2a578d3
057478d
 
 
 
 
 
 
 
aaeedf0
 
057478d
2a578d3
 
057478d
2a578d3
 
 
 
 
057478d
2a578d3
 
057478d
2a578d3
057478d
2a578d3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import platform

# os.environ['HF_HOME'] = './cache'

if platform.system() == "Windows":
    print("Windows detected. Assigning cache directory to Transformers in AppData\Local.")
    transformers_cache_directory = os.path.join(os.getenv('LOCALAPPDATA'), 'transformers_cache')
    if not os.path.exists(transformers_cache_directory):
        try:
            os.mkdir(transformers_cache_directory)
            print(f"First launch. Directory '{transformers_cache_directory}' created successfully.")
        except OSError as e:
            print(f"Error creating directory '{transformers_cache_directory}': {e}")
    else:
        print(f"Directory '{transformers_cache_directory}' already exists.")
    os.environ['TRANSFORMERS_CACHE'] = transformers_cache_directory
    print("Environment variable assigned.")
    del transformers_cache_directory

else:
    print("Windows not detected. Assignment of Transformers cache directory not necessary.")



from flask import Flask, render_template, request, jsonify

app = Flask(__name__)


@app.route('/')
def index():
    # sentiment_analysis = pipeline("sentiment-analysis")
    # result = sentiment_analysis("I absolutely love this product!")

    return render_template('index.html', name="aaa");
    # return render_template('index.html', res=jsonify({"sentiment": result[0]["label"], "score": result[0]["score"]}))
    
import torch
from transformers import pipeline
from transformers import DonutProcessor, VisionEncoderDecoderModel
from datasets import load_dataset
from PIL import Image



# classifier_doctype_processor = DonutProcessor.from_pretrained("calumpianojericho/donutclassifier_acctdocs_by_doctype")
# classifier_doctype_model = VisionEncoderDecoderModel.from_pretrained("calumpianojericho/donutclassifier_acctdocs_by_doctype")

# # Load the sentiment analysis model
# sentiment_analysis = pipeline("sentiment-analysis")

# @app.route("/analyze", methods=["POST"])
# def analyze_sentiment():
#     try:
#         data = request.json
#         text = data["text"]

#         # Perform sentiment analysis
#         result = sentiment_analysis(text)

#         return jsonify({"sentiment": result[0]["label"], "score": result[0]["score"]})

#     except Exception as e:
#         return jsonify({"error": str(e)}), 500