Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
@@ -102,7 +102,7 @@ async def convert_pdf_to_images(pdf_path):
|
|
102 |
os.remove(pdf_path)
|
103 |
|
104 |
async def send_image_to_telegram(image_path, caption):
|
105 |
-
""" Sends an image to Telegram Bot
|
106 |
try:
|
107 |
with open(image_path, "rb") as img_file:
|
108 |
message = await bot.send_photo(
|
@@ -110,14 +110,19 @@ async def send_image_to_telegram(image_path, caption):
|
|
110 |
photo=img_file,
|
111 |
caption=caption
|
112 |
)
|
113 |
-
#
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
117 |
except Exception as e:
|
118 |
logger.error(f"Error sending image: {e}")
|
119 |
return None
|
120 |
|
|
|
121 |
if __name__ == "__main__":
|
122 |
import uvicorn
|
123 |
uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info", reload=True)
|
|
|
102 |
os.remove(pdf_path)
|
103 |
|
104 |
async def send_image_to_telegram(image_path, caption):
|
105 |
+
""" Sends an image to Telegram Bot and returns the direct image URL """
|
106 |
try:
|
107 |
with open(image_path, "rb") as img_file:
|
108 |
message = await bot.send_photo(
|
|
|
110 |
photo=img_file,
|
111 |
caption=caption
|
112 |
)
|
113 |
+
# Extract the direct URL of the uploaded image
|
114 |
+
image_url = message.photo[-1].file_id # Get the highest quality image ID
|
115 |
+
|
116 |
+
# Generate the direct file link
|
117 |
+
file_info = await bot.get_file(image_url)
|
118 |
+
direct_link = f"https://api.telegram.org/file/bot{BOT_TOKEN}/{file_info.file_path}"
|
119 |
+
|
120 |
+
return direct_link
|
121 |
except Exception as e:
|
122 |
logger.error(f"Error sending image: {e}")
|
123 |
return None
|
124 |
|
125 |
+
|
126 |
if __name__ == "__main__":
|
127 |
import uvicorn
|
128 |
uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info", reload=True)
|