Update app.py
Browse files
app.py
CHANGED
|
@@ -1072,13 +1072,44 @@ async def _download_upscaled_image(upscaled_url: str, cookies_dict: dict) -> tup
|
|
| 1072 |
import traceback
|
| 1073 |
traceback.print_exc()
|
| 1074 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1075 |
# Converter para base64
|
| 1076 |
img_base64 = base64.b64encode(img_content).decode('utf-8')
|
| 1077 |
content_type = img_response.headers.get('content-type', 'image/png')
|
| 1078 |
|
| 1079 |
print(f"✅ Imagem processada e convertida para base64 ({len(img_base64)} chars)")
|
| 1080 |
|
| 1081 |
-
return img_base64, content_type,
|
| 1082 |
|
| 1083 |
|
| 1084 |
@app.get("/upscale")
|
|
|
|
| 1072 |
import traceback
|
| 1073 |
traceback.print_exc()
|
| 1074 |
|
| 1075 |
+
# Fazer upload para a API externa
|
| 1076 |
+
final_image_url = download_url
|
| 1077 |
+
try:
|
| 1078 |
+
print(f"☁️ Fazendo upload da imagem sem marca d'água para https://habulaj-recurve-videos-new.hf.space/upload")
|
| 1079 |
+
content_type_for_upload = img_response.headers.get('content-type', 'image/png')
|
| 1080 |
+
filename = f"image_{int(time.time())}.png"
|
| 1081 |
+
if "jpeg" in content_type_for_upload or "jpg" in content_type_for_upload:
|
| 1082 |
+
filename = f"image_{int(time.time())}.jpg"
|
| 1083 |
+
|
| 1084 |
+
files = {
|
| 1085 |
+
'files': (filename, img_content, content_type_for_upload)
|
| 1086 |
+
}
|
| 1087 |
+
data = {
|
| 1088 |
+
'long_duration': 'yes'
|
| 1089 |
+
}
|
| 1090 |
+
|
| 1091 |
+
upload_response = requests.post("https://habulaj-recurve-videos-new.hf.space/upload", files=files, data=data, timeout=60)
|
| 1092 |
+
upload_response.raise_for_status()
|
| 1093 |
+
upload_data = upload_response.json()
|
| 1094 |
+
|
| 1095 |
+
if "url" in upload_data:
|
| 1096 |
+
final_image_url = upload_data["url"]
|
| 1097 |
+
print(f"✅ Upload concluído: {final_image_url}")
|
| 1098 |
+
else:
|
| 1099 |
+
print(f"⚠️ Resposta de upload inesperada: {upload_data}")
|
| 1100 |
+
|
| 1101 |
+
except Exception as e:
|
| 1102 |
+
print(f"⚠️ Erro ao fazer upload da imagem: {e}")
|
| 1103 |
+
import traceback
|
| 1104 |
+
traceback.print_exc()
|
| 1105 |
+
|
| 1106 |
# Converter para base64
|
| 1107 |
img_base64 = base64.b64encode(img_content).decode('utf-8')
|
| 1108 |
content_type = img_response.headers.get('content-type', 'image/png')
|
| 1109 |
|
| 1110 |
print(f"✅ Imagem processada e convertida para base64 ({len(img_base64)} chars)")
|
| 1111 |
|
| 1112 |
+
return img_base64, content_type, final_image_url
|
| 1113 |
|
| 1114 |
|
| 1115 |
@app.get("/upscale")
|