Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +18 -16
- grammar_checker.py +0 -1
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import os
|
|
| 2 |
import logging
|
| 3 |
import sys
|
| 4 |
import argparse
|
|
|
|
|
|
|
| 5 |
from fastapi import FastAPI, File, Form, UploadFile, HTTPException, BackgroundTasks
|
| 6 |
from fastapi.responses import JSONResponse, FileResponse
|
| 7 |
from fastapi.staticfiles import StaticFiles
|
|
@@ -72,24 +74,24 @@ def check_grammar_quiz(
|
|
| 72 |
output_path = os.path.join(temp_dir, output_filename)
|
| 73 |
|
| 74 |
# Save uploaded file
|
| 75 |
-
try:
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
except Exception as e:
|
| 79 |
-
|
| 80 |
|
| 81 |
# Process the file
|
| 82 |
-
try:
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
except Exception as e:
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
|
| 95 |
def cleanup_temp_files(temp_dir: str):
|
|
|
|
| 2 |
import logging
|
| 3 |
import sys
|
| 4 |
import argparse
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
load_dotenv()
|
| 7 |
from fastapi import FastAPI, File, Form, UploadFile, HTTPException, BackgroundTasks
|
| 8 |
from fastapi.responses import JSONResponse, FileResponse
|
| 9 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 74 |
output_path = os.path.join(temp_dir, output_filename)
|
| 75 |
|
| 76 |
# Save uploaded file
|
| 77 |
+
# try:
|
| 78 |
+
with open(input_path, "wb") as buffer:
|
| 79 |
+
shutil.copyfileobj(file.file, buffer)
|
| 80 |
+
# except Exception as e:
|
| 81 |
+
# raise HTTPException(status_code=500, detail=f"Error saving file: {str(e)}")
|
| 82 |
|
| 83 |
# Process the file
|
| 84 |
+
# try:
|
| 85 |
+
result_file, processed_records = process_grammar_check(input_path, output_path, limit)
|
| 86 |
+
background_tasks.add_task(cleanup_temp_files, temp_dir)
|
| 87 |
+
return GrammarCheckResponse(
|
| 88 |
+
output_file=result_file,
|
| 89 |
+
message="Grammar check completed successfully",
|
| 90 |
+
records=processed_records
|
| 91 |
+
)
|
| 92 |
+
# except Exception as e:
|
| 93 |
+
# background_tasks.add_task(cleanup_temp_files, temp_dir)
|
| 94 |
+
# raise HTTPException(status_code=500, detail=f"Error processing file: {str(e)}")
|
| 95 |
|
| 96 |
|
| 97 |
def cleanup_temp_files(temp_dir: str):
|
grammar_checker.py
CHANGED
|
@@ -26,7 +26,6 @@ llm = AzureChatOpenAI(
|
|
| 26 |
azure_endpoint=AZURE_OPENAI_ENDPOINT,
|
| 27 |
azure_deployment=AZURE_OPENAI_DEPLOYMENT_NAME,
|
| 28 |
api_version=AZURE_OPENAI_API_VERSION,
|
| 29 |
-
model="gpt-4o",
|
| 30 |
)
|
| 31 |
# Constants for text splitting
|
| 32 |
CHUNK_SIZE = 1000 # Approximate characters per page
|
|
|
|
| 26 |
azure_endpoint=AZURE_OPENAI_ENDPOINT,
|
| 27 |
azure_deployment=AZURE_OPENAI_DEPLOYMENT_NAME,
|
| 28 |
api_version=AZURE_OPENAI_API_VERSION,
|
|
|
|
| 29 |
)
|
| 30 |
# Constants for text splitting
|
| 31 |
CHUNK_SIZE = 1000 # Approximate characters per page
|