Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
from fastapi import FastAPI, UploadFile, File, Form, HTTPException, Request
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.responses import RedirectResponse, JSONResponse, HTMLResponse
|
|
@@ -61,7 +60,7 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
| 61 |
app.mount("/images", StaticFiles(directory="images"), name="images")
|
| 62 |
|
| 63 |
# Gemini API Configuration
|
| 64 |
-
API_KEY = "AIzaSyCwmgD8KxzWiuivtySNtcZF_rfTvx9s9sY"
|
| 65 |
genai.configure(api_key=API_KEY)
|
| 66 |
|
| 67 |
# Model configurations
|
|
@@ -193,7 +192,13 @@ def translate_text(text: str, target_language: str):
|
|
| 193 |
early_stopping=True
|
| 194 |
)
|
| 195 |
translated_text = translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
| 196 |
-
logger
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
def detect_intent(text: str = None, file: UploadFile = None) -> tuple[str, str]:
|
| 199 |
"""Enhanced intent detection with dynamic translation and file translation support"""
|
|
@@ -379,7 +384,7 @@ async def process_input(
|
|
| 379 |
|
| 380 |
content = await extract_text_from_file(file)
|
| 381 |
if not content.strip():
|
| 382 |
-
raise HTTPException(status_code=400, detail="
|
| 383 |
|
| 384 |
# Split content into chunks to handle large files
|
| 385 |
max_chunk_size = 512
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File, Form, HTTPException, Request
|
| 2 |
from fastapi.staticfiles import StaticFiles
|
| 3 |
from fastapi.responses import RedirectResponse, JSONResponse, HTMLResponse
|
|
|
|
| 60 |
app.mount("/images", StaticFiles(directory="images"), name="images")
|
| 61 |
|
| 62 |
# Gemini API Configuration
|
| 63 |
+
API_KEY = "AIzaSyCwmgD8KxzWiuivtySNtcZF_rfTvx9s9sY"
|
| 64 |
genai.configure(api_key=API_KEY)
|
| 65 |
|
| 66 |
# Model configurations
|
|
|
|
| 192 |
early_stopping=True
|
| 193 |
)
|
| 194 |
translated_text = translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
|
| 195 |
+
logger.info(f"Translation took {time.time() - start_time:.2f} seconds")
|
| 196 |
+
|
| 197 |
+
return translated_text
|
| 198 |
+
|
| 199 |
+
except Exception as e:
|
| 200 |
+
logger.error(f"Translation error: {str(e)}", exc_info=True)
|
| 201 |
+
return f"Translation error: {str(e)}"
|
| 202 |
|
| 203 |
def detect_intent(text: str = None, file: UploadFile = None) -> tuple[str, str]:
|
| 204 |
"""Enhanced intent detection with dynamic translation and file translation support"""
|
|
|
|
| 384 |
|
| 385 |
content = await extract_text_from_file(file)
|
| 386 |
if not content.strip():
|
| 387 |
+
raise HTTPException(status_code=400, detail="No text could be extracted from the file")
|
| 388 |
|
| 389 |
# Split content into chunks to handle large files
|
| 390 |
max_chunk_size = 512
|