Ali Abdullah commited on
Commit
c5e78bf
·
verified ·
1 Parent(s): 08c7be8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -2
main.py CHANGED
@@ -107,13 +107,18 @@ async def chat_with_url(data: URLQuery):
107
  async def extract_text_from_image(file: UploadFile = File(...)):
108
  try:
109
  contents = await file.read()
110
- image = Image.open(io.BytesIO(contents)).convert("RGB")
111
- text = pytesseract.image_to_string(image)
 
 
 
 
112
  return {"answer": text.strip() or "⚠️ No text extracted."}
113
  except Exception as e:
114
  return JSONResponse(status_code=500, content={"error": str(e)})
115
 
116
 
 
117
  # ---------- Audio Transcription Endpoint ----------
118
  @app.post("/transcribe-audio")
119
  async def transcribe_audio(file: UploadFile = File(...)):
 
107
  async def extract_text_from_image(file: UploadFile = File(...)):
108
  try:
109
  contents = await file.read()
110
+
111
+ # Load and preprocess image
112
+ image = Image.open(io.BytesIO(contents)).convert("L") # Grayscale
113
+ image = image.resize((image.width * 2, image.height * 2)) # Upscale for better OCR
114
+
115
+ text = pytesseract.image_to_string(image, lang='eng')
116
  return {"answer": text.strip() or "⚠️ No text extracted."}
117
  except Exception as e:
118
  return JSONResponse(status_code=500, content={"error": str(e)})
119
 
120
 
121
+
122
  # ---------- Audio Transcription Endpoint ----------
123
  @app.post("/transcribe-audio")
124
  async def transcribe_audio(file: UploadFile = File(...)):