adarshb3 / Virtual-Try-On-Application-using-Flask-Twilio-and-Gradio

This repository contains the code for a virtual try-on application built using Flask, Twilio's WhatsApp API, and Gradio's virtual try-on model. Users can send images via WhatsApp to try on garments virtually, and the results are sent back to them.
308 stars 32 forks source link

405 ngrok #3

Closed jadechoghari closed 10 hours ago

jadechoghari commented 1 day ago

Hello @adarshb3 - awesome work 🔥 - i was trying to replicate the work however i'm getting the following 405 error every time i sent to the new endpoint on Whatsapp: POST / HTTP/1.1" 405

For context regarding deploying in ngrok i'm doing the following: 1- Signing up in ngrok,authenticating : ngrok authtoken, and wrapping up the local port:

from pyngrok import ngrok
if __name__ == '__main__':
    port = 8000
    public_url = ngrok.connect(port)
    print(f"ngrok tunnel URL: {public_url}")

    # run the Flask app
    app.run(port=port)

I also authenticated everything in Twilio (working), (endpoint regisetred):

Loaded as API: https://nymbo-virtual-try-on.hf.space/ ✔
ngrok tunnel URL: NgrokTunnel: "https://xxxx-xxxx-xxx-xxx-xxx.ngrok-free.app/" -> "http://localhost:8000/"
 * Serving Flask app 'app'
 * Debug mode: off

That's a super cool project - any help is appreciated!

adarshb3 commented 1 day ago

Hello @jadechoghari ! Thanks for reaching out and for the kind words about the project! 🔥

Update the Twilio Webhook URL to point to the /webhook route specifically, like this: https://<your_ngrok_url>/webhook. You can do this in the Twilio console under your WhatsApp sandbox settings.

Have a look at this article, maybe this would help - https://www.analyticsvidhya.com/blog/2024/10/virtual-try-on-chatbot-on-whatsapp/

Let me know if you run into any more bumps — happy to help!

jadechoghari commented 1 day ago

awesome it's working thanks @adarshb3 !

jadechoghari commented 1 day ago

uplading successfully - getting this now - have you encoured that issue before? i'm getting the result image on colab- just not sending on whatsapp

Created directory: static
Image saved to: static/result.png
[2024-11-12 17:04:12,178] ERROR in app: Exception on /webhook [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/content/Virtual-Try-On-Application-using-Flask-Twilio-and-Gradio/app.py", line 70, in webhook
    send_media_message(sender_number, try_on_image_url)
  File "/content/Virtual-Try-On-Application-using-Flask-Twilio-and-Gradio/app.py", line 144, in send_media_message
    message = client.messages.create(
  File "/usr/local/lib/python3.10/dist-packages/twilio/rest/api/v2010/account/message/__init__.py", line 565, in create
    payload = self._version.create(
  File "/usr/local/lib/python3.10/dist-packages/twilio/base/version.py", line 465, in create
    return self._parse_create(method, uri, response)
  File "/usr/local/lib/python3.10/dist-packages/twilio/base/version.py", line 436, in _parse_create
    raise self.exception(method, uri, response, "Unable to create record")
twilio.base.exceptions.TwilioRestException: 
HTTP Error Your request was:

POST /Accounts/ACf779ab75f532c45474d3835c8fe9ccbf/Messages.json

Twilio returned the following information:

Unable to create record: Invalid media URL(s)

More information may be available here:

https://www.twilio.com/docs/errors/21620

127.0.0.1 - - [12/Nov/2024 17:04:12] "POST /webhook HTTP/1.1" 500 -
adarshb3 commented 1 day ago

Ngrok URL changes each time you run it. Ngrok assigns a new, unique URL for every session.

double-check that NGROK_URL in your code matches the active Ngrok URL and the same is registered in your twilio settings, and that Ngrok is still running.