Spaces:
Running
Running
- app.py +11 -0
- utils/handle_file.py +3 -2
app.py
CHANGED
@@ -2,6 +2,8 @@ import os
|
|
2 |
from flask import Flask, send_file, request, jsonify
|
3 |
from utils.handle_file import file_handler
|
4 |
from werkzeug.utils import secure_filename
|
|
|
|
|
5 |
app = Flask(__name__)
|
6 |
app.config['MAX_CONTENT_LENGTH'] = 11 * 1024 * 1024
|
7 |
|
@@ -14,6 +16,7 @@ def index():
|
|
14 |
def upload():
|
15 |
try:
|
16 |
allowed_chars = request.args.get('allowed_size')
|
|
|
17 |
if 'file' not in request.files and 'files' not in request.files:
|
18 |
return jsonify({"error": "No files uploaded"}), 400
|
19 |
if 'files' in request.files:
|
@@ -30,6 +33,14 @@ def upload():
|
|
30 |
except Exception as e:
|
31 |
return jsonify({"error": f"An error occurred: {e}"}), 500
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def main():
|
34 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
35 |
|
|
|
2 |
from flask import Flask, send_file, request, jsonify
|
3 |
from utils.handle_file import file_handler
|
4 |
from werkzeug.utils import secure_filename
|
5 |
+
from rag.RAG import rag
|
6 |
+
|
7 |
app = Flask(__name__)
|
8 |
app.config['MAX_CONTENT_LENGTH'] = 11 * 1024 * 1024
|
9 |
|
|
|
16 |
def upload():
|
17 |
try:
|
18 |
allowed_chars = request.args.get('allowed_size')
|
19 |
+
print(allowed_chars)
|
20 |
if 'file' not in request.files and 'files' not in request.files:
|
21 |
return jsonify({"error": "No files uploaded"}), 400
|
22 |
if 'files' in request.files:
|
|
|
33 |
except Exception as e:
|
34 |
return jsonify({"error": f"An error occurred: {e}"}), 500
|
35 |
|
36 |
+
|
37 |
+
@app.route('/embedding')
|
38 |
+
def embedding():
|
39 |
+
return rag.generate_embedding(
|
40 |
+
text=request.json.get("text"),
|
41 |
+
task_type=request.json.get("task_type")
|
42 |
+
)
|
43 |
+
|
44 |
def main():
|
45 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
46 |
|
utils/handle_file.py
CHANGED
@@ -115,7 +115,8 @@ class FileHandler:
|
|
115 |
try:
|
116 |
allowed_limit = self._validate_params(allowed_chars)
|
117 |
content = self.read_file(file)
|
118 |
-
|
|
|
119 |
return {"error": f"Character count ({len(content)}) exceeds the allowed limit ({allowed_limit})"}, 400
|
120 |
return rag.generate_embedding(content)
|
121 |
|
@@ -136,7 +137,7 @@ class FileHandler:
|
|
136 |
total_chars += len(content)
|
137 |
except ValueError as e:
|
138 |
return {"error": f"Error with file '{file.filename}': {str(e)}"}, 400
|
139 |
-
if
|
140 |
return {"error": f"Total character count ({total_chars}) exceeds the allowed limit ({allowed_limit})"}, 400
|
141 |
|
142 |
results = []
|
|
|
115 |
try:
|
116 |
allowed_limit = self._validate_params(allowed_chars)
|
117 |
content = self.read_file(file)
|
118 |
+
|
119 |
+
if len(content) > allowed_limit:
|
120 |
return {"error": f"Character count ({len(content)}) exceeds the allowed limit ({allowed_limit})"}, 400
|
121 |
return rag.generate_embedding(content)
|
122 |
|
|
|
137 |
total_chars += len(content)
|
138 |
except ValueError as e:
|
139 |
return {"error": f"Error with file '{file.filename}': {str(e)}"}, 400
|
140 |
+
if total_chars > allowed_limit:
|
141 |
return {"error": f"Total character count ({total_chars}) exceeds the allowed limit ({allowed_limit})"}, 400
|
142 |
|
143 |
results = []
|