Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
sachin
commited on
Commit
·
cf4b677
1
Parent(s):
53ace05
update-call
Browse files- src/server/main.py +13 -4
src/server/main.py
CHANGED
@@ -810,6 +810,7 @@ async def extract_text(
|
|
810 |
logger.error(f"Invalid JSON response from external API: {str(e)}")
|
811 |
raise HTTPException(status_code=500, detail="Invalid response format from external API")
|
812 |
|
|
|
813 |
@app.post("/v1/visual_query",
|
814 |
response_model=VisualQueryResponse,
|
815 |
summary="Visual Query with Image",
|
@@ -893,18 +894,23 @@ async def visual_query(
|
|
893 |
external_url = f"{settings.external_api_base_url}/v1/visual_query/?src_lang={decrypted_src_lang}&tgt_lang={decrypted_tgt_lang}"
|
894 |
|
895 |
try:
|
896 |
-
|
897 |
-
|
898 |
-
|
|
|
|
|
899 |
|
900 |
|
901 |
response = dwani.Vision.caption(
|
902 |
-
file_path=
|
903 |
query=decrypted_query,
|
904 |
src_lang=decrypted_src_lang,
|
905 |
tgt_lang=decrypted_tgt_lang
|
906 |
)
|
907 |
'''
|
|
|
|
|
|
|
908 |
response = requests.post(
|
909 |
external_url,
|
910 |
files=files,
|
@@ -934,6 +940,9 @@ async def visual_query(
|
|
934 |
except ValueError as e:
|
935 |
logger.error(f"Invalid JSON response: {str(e)}")
|
936 |
raise HTTPException(status_code=500, detail="Invalid response format from visual query service")
|
|
|
|
|
|
|
937 |
|
938 |
from enum import Enum
|
939 |
|
|
|
810 |
logger.error(f"Invalid JSON response from external API: {str(e)}")
|
811 |
raise HTTPException(status_code=500, detail="Invalid response format from external API")
|
812 |
|
813 |
+
import tempfile
|
814 |
@app.post("/v1/visual_query",
|
815 |
response_model=VisualQueryResponse,
|
816 |
summary="Visual Query with Image",
|
|
|
894 |
external_url = f"{settings.external_api_base_url}/v1/visual_query/?src_lang={decrypted_src_lang}&tgt_lang={decrypted_tgt_lang}"
|
895 |
|
896 |
try:
|
897 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=file.filename) as temp_file:
|
898 |
+
# Write the decrypted content to the temp file
|
899 |
+
#decrypted_content = await file.read() # Assuming decrypted_content is the file content
|
900 |
+
temp_file.write(decrypted_content)
|
901 |
+
temp_file_path = temp_file.name
|
902 |
|
903 |
|
904 |
response = dwani.Vision.caption(
|
905 |
+
file_path=temp_file_path,
|
906 |
query=decrypted_query,
|
907 |
src_lang=decrypted_src_lang,
|
908 |
tgt_lang=decrypted_tgt_lang
|
909 |
)
|
910 |
'''
|
911 |
+
files = {"file": (file.filename, decrypted_content, file.content_type)}
|
912 |
+
data = {"query": decrypted_query}
|
913 |
+
|
914 |
response = requests.post(
|
915 |
external_url,
|
916 |
files=files,
|
|
|
940 |
except ValueError as e:
|
941 |
logger.error(f"Invalid JSON response: {str(e)}")
|
942 |
raise HTTPException(status_code=500, detail="Invalid response format from visual query service")
|
943 |
+
finally:
|
944 |
+
# Clean up the temporary file
|
945 |
+
os.unlink(temp_file_path)
|
946 |
|
947 |
from enum import Enum
|
948 |
|