Ali Abdullah
commited on
Update main.py
Browse files
main.py
CHANGED
|
@@ -79,8 +79,7 @@ class URLQuery(BaseModel):
|
|
| 79 |
@app.post("/chat-with-url")
|
| 80 |
async def chat_with_url(data: URLQuery):
|
| 81 |
try:
|
| 82 |
-
|
| 83 |
-
loader = WebBaseLoader(data.url)
|
| 84 |
documents = loader.load()
|
| 85 |
web_content = "\n".join([doc.page_content for doc in documents])
|
| 86 |
|
|
@@ -94,16 +93,18 @@ async def chat_with_url(data: URLQuery):
|
|
| 94 |
return {"answer": response.choices[0].message.content}
|
| 95 |
except Exception as e:
|
| 96 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
|
| 97 |
|
| 98 |
@app.post("/extract-text-from-image")
|
| 99 |
async def extract_text_from_image(file: UploadFile = File(...)):
|
| 100 |
try:
|
| 101 |
contents = await file.read()
|
| 102 |
-
image = Image.open(io.BytesIO(contents))
|
| 103 |
text = pytesseract.image_to_string(image)
|
| 104 |
return {"answer": text.strip() or "⚠️ No text extracted."}
|
| 105 |
except Exception as e:
|
| 106 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
|
| 107 |
|
| 108 |
@app.post("/transcribe-audio")
|
| 109 |
async def transcribe_audio(file: UploadFile = File(...)):
|
|
|
|
| 79 |
@app.post("/chat-with-url")
|
| 80 |
async def chat_with_url(data: URLQuery):
|
| 81 |
try:
|
| 82 |
+
loader = WebBaseLoader(data.url, header_template={"User-Agent": "Mozilla/5.0"})
|
|
|
|
| 83 |
documents = loader.load()
|
| 84 |
web_content = "\n".join([doc.page_content for doc in documents])
|
| 85 |
|
|
|
|
| 93 |
return {"answer": response.choices[0].message.content}
|
| 94 |
except Exception as e:
|
| 95 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
| 96 |
+
|
| 97 |
|
| 98 |
@app.post("/extract-text-from-image")
|
| 99 |
async def extract_text_from_image(file: UploadFile = File(...)):
|
| 100 |
try:
|
| 101 |
contents = await file.read()
|
| 102 |
+
image = Image.open(io.BytesIO(contents)).convert("RGB")
|
| 103 |
text = pytesseract.image_to_string(image)
|
| 104 |
return {"answer": text.strip() or "⚠️ No text extracted."}
|
| 105 |
except Exception as e:
|
| 106 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
| 107 |
+
|
| 108 |
|
| 109 |
@app.post("/transcribe-audio")
|
| 110 |
async def transcribe_audio(file: UploadFile = File(...)):
|