Spaces:
Sleeping
Sleeping
Prathamesh Sable commited on
Commit ·
cca8343
1
Parent(s): d1c1737
changes made to manage session specific files and db for deletion of data
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from flask import Flask,request, jsonify,session
|
|
| 3 |
from flask import render_template
|
| 4 |
from flask_session import Session
|
| 5 |
from werkzeug.utils import secure_filename
|
|
|
|
| 6 |
|
| 7 |
from langchain.document_loaders import DirectoryLoader,PyPDFLoader,UnstructuredWordDocumentLoader,TextLoader,UnstructuredHTMLLoader,UnstructuredMarkdownLoader
|
| 8 |
|
|
@@ -10,12 +11,18 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
| 10 |
|
| 11 |
from langchain.embeddings.huggingface import HuggingFaceInferenceAPIEmbeddings
|
| 12 |
from langchain_chroma import Chroma
|
|
|
|
| 13 |
|
| 14 |
import google.generativeai as genai
|
| 15 |
|
| 16 |
from dotenv import load_dotenv
|
| 17 |
import os
|
| 18 |
import shutil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
load_dotenv()
|
| 21 |
|
|
@@ -23,6 +30,7 @@ HF_TOKEN = os.getenv('HF_TOKEN')
|
|
| 23 |
GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
|
| 24 |
CHROMA_PATH = "chroma"
|
| 25 |
UPLOAD_FOLDER = "uploads"
|
|
|
|
| 26 |
|
| 27 |
# Initialize Hugging Face embedding
|
| 28 |
hugging_face_ef = HuggingFaceInferenceAPIEmbeddings(
|
|
@@ -32,26 +40,21 @@ hugging_face_ef = HuggingFaceInferenceAPIEmbeddings(
|
|
| 32 |
genai.configure(api_key=GOOGLE_API_KEY)
|
| 33 |
llm_model = genai.GenerativeModel("gemini-1.5-flash")
|
| 34 |
|
| 35 |
-
if not os.path.exists(UPLOAD_FOLDER):
|
| 36 |
-
os.makedirs(UPLOAD_FOLDER)
|
| 37 |
-
|
| 38 |
app = Flask(__name__)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
app.config["SESSION_PERMANENT"] = True
|
| 41 |
app.config["SESSION_TYPE"] = "filesystem"
|
| 42 |
|
| 43 |
Session(app)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
persist_directory=CHROMA_PATH, embedding_function=embedding_function
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
# Add or Update the documents.
|
| 52 |
-
db.add_documents(chunks)
|
| 53 |
|
| 54 |
-
return True
|
| 55 |
|
| 56 |
def remove_file_from_chroma(file_id,CHROMA_PATH=CHROMA_PATH):
|
| 57 |
db = Chroma(persist_directory=CHROMA_PATH)
|
|
@@ -61,90 +64,108 @@ def remove_file_from_chroma(file_id,CHROMA_PATH=CHROMA_PATH):
|
|
| 61 |
return True
|
| 62 |
|
| 63 |
|
| 64 |
-
def add_file_to_chroma(file_path,file_id):
|
| 65 |
-
|
| 66 |
extension = file_path.split(".")[-1]
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
case _:
|
| 79 |
-
raise ValueError(f"Unsupported file type: {extension}")
|
| 80 |
documents = loader.load()
|
| 81 |
-
text_splitter = RecursiveCharacterTextSplitter( chunk_size=1000,
|
| 82 |
-
chunk_overlap=100,
|
| 83 |
-
length_function=len,
|
| 84 |
-
add_start_index=True)
|
| 85 |
-
texts = text_splitter.split_documents(documents)
|
| 86 |
-
# add metadata file_id to documents
|
| 87 |
-
for text in texts:
|
| 88 |
-
text.metadata["file_id"] = file_id
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
|
|
|
|
|
|
|
|
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
@app.route('/')
|
| 96 |
def index():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
return render_template('index.html') # Serve the HTML file we created
|
| 98 |
|
| 99 |
-
@app.route('/wait',methods=["POST"])
|
| 100 |
-
def wait():
|
| 101 |
-
time.sleep(int(request.form.get("time")))
|
| 102 |
-
return jsonify({"status":"ok"}),200
|
| 103 |
-
|
| 104 |
-
@app.route("/ai",methods=["POST"])
|
| 105 |
-
def aiPost():
|
| 106 |
-
print("Post /ai called")
|
| 107 |
-
json_content = request.json
|
| 108 |
-
query = json_content.get("query")
|
| 109 |
-
|
| 110 |
-
print("Query:",query)
|
| 111 |
-
|
| 112 |
-
response_answer = llm_model.generate_content(query)
|
| 113 |
-
return response_answer.text
|
| 114 |
-
|
| 115 |
# add files
|
| 116 |
@app.route('/upload-file', methods=['POST'])
|
| 117 |
def upload_file():
|
| 118 |
-
|
| 119 |
if 'file' not in request.files:
|
| 120 |
-
return jsonify({'error': 'No
|
| 121 |
|
| 122 |
file = request.files['file']
|
| 123 |
file_id = request.form.get('file_count')
|
|
|
|
| 124 |
|
| 125 |
-
if not
|
| 126 |
-
|
| 127 |
|
| 128 |
-
if file.filename:
|
| 129 |
-
# Secure the filename
|
| 130 |
-
filename = secure_filename(file.filename)
|
| 131 |
-
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
| 132 |
-
file.save(file_path)
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
# process_pdf(file_path)
|
| 138 |
-
add_file_to_chroma(file_path,file_id)
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
@app.route('/get-files',methods=["GET"])
|
| 146 |
def get_files():
|
| 147 |
-
return jsonify({"files":session.
|
| 148 |
|
| 149 |
@app.route('/chroma-status',methods=["GET"])
|
| 150 |
def chroma_status():
|
|
@@ -155,13 +176,29 @@ def chroma_status():
|
|
| 155 |
@app.route('/remove-file',methods=["POST"])
|
| 156 |
def remove_file():
|
| 157 |
file_id = request.form.get('file_id')
|
| 158 |
-
session[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
remove_file_from_chroma(file_id)
|
|
|
|
| 160 |
return jsonify({
|
| 161 |
'message': 'File deleted successfully',
|
| 162 |
'status': 'success'
|
| 163 |
}), 200
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
def main():
|
| 166 |
app.run(host="0.0.0.0",port=8000,debug=True)
|
| 167 |
|
|
|
|
| 3 |
from flask import render_template
|
| 4 |
from flask_session import Session
|
| 5 |
from werkzeug.utils import secure_filename
|
| 6 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
| 7 |
|
| 8 |
from langchain.document_loaders import DirectoryLoader,PyPDFLoader,UnstructuredWordDocumentLoader,TextLoader,UnstructuredHTMLLoader,UnstructuredMarkdownLoader
|
| 9 |
|
|
|
|
| 11 |
|
| 12 |
from langchain.embeddings.huggingface import HuggingFaceInferenceAPIEmbeddings
|
| 13 |
from langchain_chroma import Chroma
|
| 14 |
+
from chromadb import Client
|
| 15 |
|
| 16 |
import google.generativeai as genai
|
| 17 |
|
| 18 |
from dotenv import load_dotenv
|
| 19 |
import os
|
| 20 |
import shutil
|
| 21 |
+
import logging
|
| 22 |
+
|
| 23 |
+
logging.basicConfig(filename='log.txt',filemode='a', level=logging.DEBUG,
|
| 24 |
+
format='%(asctime)s - %(levelname)s - %(message)s')
|
| 25 |
+
logger = logging.getLogger()
|
| 26 |
|
| 27 |
load_dotenv()
|
| 28 |
|
|
|
|
| 30 |
GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
|
| 31 |
CHROMA_PATH = "chroma"
|
| 32 |
UPLOAD_FOLDER = "uploads"
|
| 33 |
+
SESSION_TIMEOUT = 30 * 60 # 30 minutes
|
| 34 |
|
| 35 |
# Initialize Hugging Face embedding
|
| 36 |
hugging_face_ef = HuggingFaceInferenceAPIEmbeddings(
|
|
|
|
| 40 |
genai.configure(api_key=GOOGLE_API_KEY)
|
| 41 |
llm_model = genai.GenerativeModel("gemini-1.5-flash")
|
| 42 |
|
|
|
|
|
|
|
|
|
|
| 43 |
app = Flask(__name__)
|
| 44 |
|
| 45 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 46 |
+
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
| 47 |
+
|
| 48 |
+
|
| 49 |
app.config["SESSION_PERMANENT"] = True
|
| 50 |
app.config["SESSION_TYPE"] = "filesystem"
|
| 51 |
|
| 52 |
Session(app)
|
| 53 |
|
| 54 |
+
# Initialize ChromaDB client
|
| 55 |
+
client = Client()
|
| 56 |
+
active_sessions = dict()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
|
|
|
| 58 |
|
| 59 |
def remove_file_from_chroma(file_id,CHROMA_PATH=CHROMA_PATH):
|
| 60 |
db = Chroma(persist_directory=CHROMA_PATH)
|
|
|
|
| 64 |
return True
|
| 65 |
|
| 66 |
|
| 67 |
+
def add_file_to_chroma(file_path, file_id, session_id):
|
| 68 |
+
"""Add file chunks to ChromaDB."""
|
| 69 |
extension = file_path.split(".")[-1]
|
| 70 |
+
loader_map = {
|
| 71 |
+
"pdf": PyPDFLoader,
|
| 72 |
+
"docx": UnstructuredWordDocumentLoader,
|
| 73 |
+
"txt": TextLoader,
|
| 74 |
+
"html": UnstructuredHTMLLoader,
|
| 75 |
+
"md": UnstructuredMarkdownLoader,
|
| 76 |
+
}
|
| 77 |
+
if extension not in loader_map:
|
| 78 |
+
raise ValueError(f"Unsupported file type: {extension}")
|
| 79 |
+
|
| 80 |
+
loader = loader_map[extension](file_path)
|
|
|
|
|
|
|
| 81 |
documents = loader.load()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
text_splitter = RecursiveCharacterTextSplitter(
|
| 84 |
+
chunk_size=1000,
|
| 85 |
+
chunk_overlap=100,
|
| 86 |
+
length_function=len,
|
| 87 |
+
add_start_index=True
|
| 88 |
+
)
|
| 89 |
+
texts = text_splitter.split_documents(documents)
|
| 90 |
|
| 91 |
+
# Add metadata
|
| 92 |
+
for text in texts:
|
| 93 |
+
text.metadata.update({"file_id": file_id, "session_id": session_id})
|
| 94 |
|
| 95 |
+
# Save to ChromaDB
|
| 96 |
+
db = Chroma(persist_directory=CHROMA_PATH, embedding_function=hugging_face_ef)
|
| 97 |
+
db.add_documents(texts)
|
| 98 |
+
logger.info(f"Added file '{file_path}' to ChromaDB for session '{session_id}'.")
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# Clean up expired files and ChromaDB collections
|
| 102 |
+
def cleanup_resources():
|
| 103 |
+
"""Clean up expired files and ChromaDB collections."""
|
| 104 |
+
now = time.time()
|
| 105 |
+
for session_id, session_data in list(active_sessions.items()):
|
| 106 |
+
if now - session_data['last_accessed'] > SESSION_TIMEOUT:
|
| 107 |
+
# Remove files
|
| 108 |
+
files = session_data.get('files', {})
|
| 109 |
+
for file_id, (file_path, filename) in files.items():
|
| 110 |
+
if os.path.exists(file_path):
|
| 111 |
+
os.remove(file_path)
|
| 112 |
+
logger.info(f"Deleted file: {file_path}")
|
| 113 |
+
|
| 114 |
+
# Remove ChromaDB chunks
|
| 115 |
+
db = Chroma(persist_directory=CHROMA_PATH)
|
| 116 |
+
db.delete(where={"session_id": session_id})
|
| 117 |
+
logger.info(f"Deleted ChromaDB chunks for session: {session_id}")
|
| 118 |
+
|
| 119 |
+
# Remove session
|
| 120 |
+
del active_sessions[session_id]
|
| 121 |
+
|
| 122 |
+
# Start the scheduler
|
| 123 |
+
scheduler = BackgroundScheduler()
|
| 124 |
+
scheduler.add_job(cleanup_resources, 'interval', minutes=5) # Run every 5 minutes
|
| 125 |
+
scheduler.start()
|
| 126 |
|
| 127 |
@app.route('/')
|
| 128 |
def index():
|
| 129 |
+
session_id = session.sid
|
| 130 |
+
if session_id not in active_sessions:
|
| 131 |
+
active_sessions[session_id] = {
|
| 132 |
+
'last_accessed': time.time(),
|
| 133 |
+
'files': dict()
|
| 134 |
+
}
|
| 135 |
return render_template('index.html') # Serve the HTML file we created
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
# add files
|
| 138 |
@app.route('/upload-file', methods=['POST'])
|
| 139 |
def upload_file():
|
| 140 |
+
"""Handle file uploads."""
|
| 141 |
if 'file' not in request.files:
|
| 142 |
+
return jsonify({'error': 'No file in request', 'status': 'error'}), 400
|
| 143 |
|
| 144 |
file = request.files['file']
|
| 145 |
file_id = request.form.get('file_count')
|
| 146 |
+
session_id = session.sid
|
| 147 |
|
| 148 |
+
if not file or not file.filename:
|
| 149 |
+
return jsonify({'error': 'No file selected', 'status': 'error'}), 400
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
filename = secure_filename(file.filename)
|
| 153 |
+
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
| 154 |
+
file.save(file_path)
|
|
|
|
|
|
|
| 155 |
|
| 156 |
+
# Update session data
|
| 157 |
+
active_sessions[session_id]['files'][file_id] = (file_path,file.filename)
|
| 158 |
+
active_sessions[session_id]['last_accessed'] = time.time()
|
| 159 |
+
|
| 160 |
+
# Add file chunks to ChromaDB
|
| 161 |
+
add_file_to_chroma(file_path, file_id, session_id)
|
| 162 |
+
|
| 163 |
+
return jsonify({'message': 'File uploaded successfully', 'status': 'success'}), 200
|
| 164 |
+
|
| 165 |
|
| 166 |
@app.route('/get-files',methods=["GET"])
|
| 167 |
def get_files():
|
| 168 |
+
return jsonify({"files":active_sessions[session.sid]['files']}),200
|
| 169 |
|
| 170 |
@app.route('/chroma-status',methods=["GET"])
|
| 171 |
def chroma_status():
|
|
|
|
| 176 |
@app.route('/remove-file',methods=["POST"])
|
| 177 |
def remove_file():
|
| 178 |
file_id = request.form.get('file_id')
|
| 179 |
+
if file_id in active_sessions[session.sid]['files']:
|
| 180 |
+
file_path = active_sessions[session.sid]['files'][file_id][0]
|
| 181 |
+
# remove file from upload folder
|
| 182 |
+
if os.path.exists(file_path):
|
| 183 |
+
os.remove(file_path)
|
| 184 |
+
logger.info(f"Deleted file: {file_path}")
|
| 185 |
+
# Remove file from session
|
| 186 |
+
del active_sessions[session.sid]['files'][file_id]
|
| 187 |
+
else:
|
| 188 |
+
logger.info(f"File not found in session: {file_id}")
|
| 189 |
+
|
| 190 |
remove_file_from_chroma(file_id)
|
| 191 |
+
|
| 192 |
return jsonify({
|
| 193 |
'message': 'File deleted successfully',
|
| 194 |
'status': 'success'
|
| 195 |
}), 200
|
| 196 |
|
| 197 |
+
# Ensure scheduler stops on app exit
|
| 198 |
+
@app.teardown_appcontext
|
| 199 |
+
def shutdown_scheduler(exception=None):
|
| 200 |
+
scheduler.shutdown()
|
| 201 |
+
|
| 202 |
def main():
|
| 203 |
app.run(host="0.0.0.0",port=8000,debug=True)
|
| 204 |
|
log.txt
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2024-12-06 14:02:03,186 - INFO - Anonymized telemetry enabled. See https://docs.trychroma.com/telemetry for more information.
|
| 2 |
+
2024-12-06 14:02:03,499 - DEBUG - Starting component System
|
| 3 |
+
2024-12-06 14:02:03,499 - DEBUG - Starting component Posthog
|
| 4 |
+
2024-12-06 14:02:03,499 - DEBUG - Starting component OpenTelemetryClient
|
| 5 |
+
2024-12-06 14:02:03,499 - DEBUG - Starting component SqliteDB
|
| 6 |
+
2024-12-06 14:02:03,501 - DEBUG - Starting component SimpleQuotaEnforcer
|
| 7 |
+
2024-12-06 14:02:03,501 - DEBUG - Starting component SimpleRateLimitEnforcer
|
| 8 |
+
2024-12-06 14:02:03,501 - DEBUG - Starting component LocalSegmentManager
|
| 9 |
+
2024-12-06 14:02:03,501 - DEBUG - Starting component LocalExecutor
|
| 10 |
+
2024-12-06 14:02:03,501 - DEBUG - Starting component SegmentAPI
|
| 11 |
+
2024-12-06 14:02:03,519 - DEBUG - Looking up time zone info from registry
|
| 12 |
+
2024-12-06 14:02:03,542 - INFO - Adding job tentatively -- it will be properly scheduled when the scheduler starts
|
| 13 |
+
2024-12-06 14:02:03,542 - INFO - Added job "cleanup_resources" to job store "default"
|
| 14 |
+
2024-12-06 14:02:03,542 - INFO - Scheduler started
|
| 15 |
+
2024-12-06 14:02:03,542 - DEBUG - Looking for jobs to run
|
| 16 |
+
2024-12-06 14:02:03,548 - DEBUG - Next wakeup is due at 2024-12-06 14:07:03.542688+05:30 (in 299.993982 seconds)
|
| 17 |
+
2024-12-06 14:02:03,567 - WARNING - * Debugger is active!
|
| 18 |
+
2024-12-06 14:02:03,567 - INFO - * Debugger PIN: 471-334-865
|
| 19 |
+
2024-12-06 14:02:04,024 - DEBUG - Starting new HTTPS connection (1): us.i.posthog.com:443
|
| 20 |
+
2024-12-06 14:02:05,409 - DEBUG - https://us.i.posthog.com:443 "POST /batch/ HTTP/11" 200 15
|
| 21 |
+
2024-12-06 14:07:03,556 - DEBUG - Looking for jobs to run
|
| 22 |
+
2024-12-06 14:07:03,556 - INFO - Running job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:07:03 IST)" (scheduled at 2024-12-06 14:07:03.542688+05:30)
|
| 23 |
+
2024-12-06 14:07:03,556 - DEBUG - Next wakeup is due at 2024-12-06 14:12:03.542688+05:30 (in 299.985749 seconds)
|
| 24 |
+
2024-12-06 14:07:03,565 - INFO - Deleted expired file: uploads\20_DSA_patterns_.pdf
|
| 25 |
+
2024-12-06 14:07:03,565 - INFO - Deleted expired file: uploads\a16-ahn.pdf
|
| 26 |
+
2024-12-06 14:07:03,565 - INFO - Deleted expired file: uploads\blank_page.pdf
|
| 27 |
+
2024-12-06 14:07:03,565 - INFO - Deleted expired file: uploads\Complete_Git_Cheat_Sheet.pdf
|
| 28 |
+
2024-12-06 14:07:03,571 - INFO - Deleted expired file: uploads\E150000182706715682136.PDF
|
| 29 |
+
2024-12-06 14:07:03,573 - INFO - Deleted expired file: uploads\Prathamesh_Sable_Resume.pdf
|
| 30 |
+
2024-12-06 14:07:03,573 - INFO - Deleted expired file: uploads\README.md
|
| 31 |
+
2024-12-06 14:07:03,573 - INFO - Job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:12:03 IST)" executed successfully
|
| 32 |
+
2024-12-06 14:12:03,550 - DEBUG - Looking for jobs to run
|
| 33 |
+
2024-12-06 14:12:03,550 - DEBUG - Next wakeup is due at 2024-12-06 14:17:03.542688+05:30 (in 299.992333 seconds)
|
| 34 |
+
2024-12-06 14:12:03,550 - INFO - Running job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:17:03 IST)" (scheduled at 2024-12-06 14:12:03.542688+05:30)
|
| 35 |
+
2024-12-06 14:12:03,550 - INFO - Job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:17:03 IST)" executed successfully
|
| 36 |
+
2024-12-06 14:17:03,550 - DEBUG - Looking for jobs to run
|
| 37 |
+
2024-12-06 14:17:03,550 - DEBUG - Next wakeup is due at 2024-12-06 14:22:03.542688+05:30 (in 299.991993 seconds)
|
| 38 |
+
2024-12-06 14:17:03,550 - INFO - Running job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:22:03 IST)" (scheduled at 2024-12-06 14:17:03.542688+05:30)
|
| 39 |
+
2024-12-06 14:17:03,550 - INFO - Job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:22:03 IST)" executed successfully
|
| 40 |
+
2024-12-06 14:22:03,548 - DEBUG - Looking for jobs to run
|
| 41 |
+
2024-12-06 14:22:03,549 - DEBUG - Next wakeup is due at 2024-12-06 14:27:03.542688+05:30 (in 299.992908 seconds)
|
| 42 |
+
2024-12-06 14:22:03,549 - INFO - Running job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:27:03 IST)" (scheduled at 2024-12-06 14:22:03.542688+05:30)
|
| 43 |
+
2024-12-06 14:22:03,549 - INFO - Job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:27:03 IST)" executed successfully
|
| 44 |
+
2024-12-06 14:27:03,559 - DEBUG - Looking for jobs to run
|
| 45 |
+
2024-12-06 14:27:03,559 - DEBUG - Next wakeup is due at 2024-12-06 14:32:03.542688+05:30 (in 299.983279 seconds)
|
| 46 |
+
2024-12-06 14:27:03,559 - INFO - Running job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:32:03 IST)" (scheduled at 2024-12-06 14:27:03.542688+05:30)
|
| 47 |
+
2024-12-06 14:27:03,559 - INFO - Job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:32:03 IST)" executed successfully
|
| 48 |
+
2024-12-06 14:32:03,558 - DEBUG - Looking for jobs to run
|
| 49 |
+
2024-12-06 14:32:03,558 - DEBUG - Next wakeup is due at 2024-12-06 14:37:03.542688+05:30 (in 299.983849 seconds)
|
| 50 |
+
2024-12-06 14:32:03,565 - INFO - Running job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:37:03 IST)" (scheduled at 2024-12-06 14:32:03.542688+05:30)
|
| 51 |
+
2024-12-06 14:32:03,565 - INFO - Job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:37:03 IST)" executed successfully
|
| 52 |
+
2024-12-06 14:37:03,558 - DEBUG - Looking for jobs to run
|
| 53 |
+
2024-12-06 14:37:03,566 - DEBUG - Next wakeup is due at 2024-12-06 14:42:03.542688+05:30 (in 299.976199 seconds)
|
| 54 |
+
2024-12-06 14:37:03,566 - INFO - Running job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:42:03 IST)" (scheduled at 2024-12-06 14:37:03.542688+05:30)
|
| 55 |
+
2024-12-06 14:37:03,568 - INFO - Job "cleanup_resources (trigger: interval[0:05:00], next run at: 2024-12-06 14:42:03 IST)" executed successfully
|
| 56 |
+
2024-12-06 14:40:58,432 - INFO - * Detected change in 'D:\\Coding\\Multi-File-Chatting\\app.py', reloading
|
| 57 |
+
2024-12-06 14:41:07,871 - INFO - Anonymized telemetry enabled. See https://docs.trychroma.com/telemetry for more information.
|
| 58 |
+
2024-12-06 14:41:08,298 - DEBUG - Starting component System
|
| 59 |
+
2024-12-06 14:41:08,298 - DEBUG - Starting component Posthog
|
| 60 |
+
2024-12-06 14:41:08,298 - DEBUG - Starting component OpenTelemetryClient
|
| 61 |
+
2024-12-06 14:41:08,298 - DEBUG - Starting component SqliteDB
|
| 62 |
+
2024-12-06 14:41:08,322 - DEBUG - Starting component SimpleQuotaEnforcer
|
| 63 |
+
2024-12-06 14:41:08,322 - DEBUG - Starting component SimpleRateLimitEnforcer
|
| 64 |
+
2024-12-06 14:41:08,323 - DEBUG - Starting component LocalSegmentManager
|
| 65 |
+
2024-12-06 14:41:08,323 - DEBUG - Starting component LocalExecutor
|
| 66 |
+
2024-12-06 14:41:08,323 - DEBUG - Starting component SegmentAPI
|
| 67 |
+
2024-12-06 14:41:08,327 - DEBUG - Looking up time zone info from registry
|
| 68 |
+
2024-12-06 14:41:08,340 - INFO - Adding job tentatively -- it will be properly scheduled when the scheduler starts
|
| 69 |
+
2024-12-06 14:41:08,340 - INFO - Added job "cleanup_resources" to job store "default"
|
| 70 |
+
2024-12-06 14:41:08,341 - INFO - Scheduler started
|
| 71 |
+
2024-12-06 14:41:08,341 - DEBUG - Looking for jobs to run
|
| 72 |
+
2024-12-06 14:41:08,344 - DEBUG - Next wakeup is due at 2024-12-06 14:46:08.340975+05:30 (in 299.996005 seconds)
|
| 73 |
+
2024-12-06 14:41:08,371 - WARNING - * Debugger is active!
|
| 74 |
+
2024-12-06 14:41:08,381 - INFO - * Debugger PIN: 471-334-865
|
| 75 |
+
2024-12-06 14:41:08,839 - DEBUG - Starting new HTTPS connection (1): us.i.posthog.com:443
|
| 76 |
+
2024-12-06 14:41:10,082 - DEBUG - https://us.i.posthog.com:443 "POST /batch/ HTTP/11" 200 15
|
| 77 |
+
2024-12-06 14:45:48,701 - INFO - * Detected change in 'D:\\Coding\\Multi-File-Chatting\\app.py', reloading
|
| 78 |
+
2024-12-06 14:45:56,500 - INFO - Anonymized telemetry enabled. See https://docs.trychroma.com/telemetry for more information.
|
| 79 |
+
2024-12-06 14:45:56,772 - DEBUG - Starting component System
|
| 80 |
+
2024-12-06 14:45:56,772 - DEBUG - Starting component Posthog
|
| 81 |
+
2024-12-06 14:45:56,772 - DEBUG - Starting component OpenTelemetryClient
|
| 82 |
+
2024-12-06 14:45:56,772 - DEBUG - Starting component SqliteDB
|
| 83 |
+
2024-12-06 14:45:56,799 - DEBUG - Starting component SimpleQuotaEnforcer
|
| 84 |
+
2024-12-06 14:45:56,799 - DEBUG - Starting component SimpleRateLimitEnforcer
|
| 85 |
+
2024-12-06 14:45:56,799 - DEBUG - Starting component LocalSegmentManager
|
| 86 |
+
2024-12-06 14:45:56,799 - DEBUG - Starting component LocalExecutor
|
| 87 |
+
2024-12-06 14:45:56,799 - DEBUG - Starting component SegmentAPI
|
| 88 |
+
2024-12-06 14:45:56,802 - DEBUG - Looking up time zone info from registry
|
| 89 |
+
2024-12-06 14:45:56,802 - INFO - Adding job tentatively -- it will be properly scheduled when the scheduler starts
|
| 90 |
+
2024-12-06 14:45:56,802 - INFO - Added job "cleanup_resources" to job store "default"
|
| 91 |
+
2024-12-06 14:45:56,802 - INFO - Scheduler started
|
| 92 |
+
2024-12-06 14:45:56,802 - DEBUG - Looking for jobs to run
|
| 93 |
+
2024-12-06 14:45:56,802 - DEBUG - Next wakeup is due at 2024-12-06 14:50:56.802779+05:30 (in 300.000000 seconds)
|
| 94 |
+
2024-12-06 14:45:56,818 - WARNING - * Debugger is active!
|
| 95 |
+
2024-12-06 14:45:56,834 - INFO - * Debugger PIN: 471-334-865
|
| 96 |
+
2024-12-06 14:45:57,307 - DEBUG - Starting new HTTPS connection (1): us.i.posthog.com:443
|
| 97 |
+
2024-12-06 14:45:58,410 - INFO - * Detected change in 'D:\\Coding\\Multi-File-Chatting\\utils.py', reloading
|
| 98 |
+
2024-12-06 14:45:58,591 - DEBUG - https://us.i.posthog.com:443 "POST /batch/ HTTP/11" 200 15
|
requirements.txt
CHANGED
|
@@ -15,4 +15,5 @@ markdown
|
|
| 15 |
python-docx
|
| 16 |
flask
|
| 17 |
werkzeug
|
| 18 |
-
Flask-Session
|
|
|
|
|
|
| 15 |
python-docx
|
| 16 |
flask
|
| 17 |
werkzeug
|
| 18 |
+
Flask-Session
|
| 19 |
+
apscheduler
|
utils.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
@app.route('/wait',methods=["POST"])
|
| 3 |
+
def wait():
|
| 4 |
+
time.sleep(int(request.form.get("time")))
|
| 5 |
+
return jsonify({"status":"ok"}),200
|
| 6 |
+
|
| 7 |
+
@app.route("/ai",methods=["POST"])
|
| 8 |
+
def aiPost():
|
| 9 |
+
print("Post /ai called")
|
| 10 |
+
json_content = request.json
|
| 11 |
+
query = json_content.get("query")
|
| 12 |
+
|
| 13 |
+
print("Query:",query)
|
| 14 |
+
|
| 15 |
+
response_answer = llm_model.generate_content(query)
|
| 16 |
+
return response_answer.text
|