{"slug": "deploying-gradio-on-ubuntu-22-04", "title": "Deploying Gradio on Ubuntu 22.04", "summary": "A developer has published a guide for deploying a GFPGAN-powered face-restoration demo using Gradio on Ubuntu 22.04. The setup includes running the app as a systemd service and exposing it through Nginx with TLS. The guide covers installing dependencies, creating the app, and configuring the server.", "body_md": "Gradio is a Python library for wrapping any ML model in a web interface, ready to deploy and scale as an app. This guide builds a GFPGAN-powered face-restoration demo with Gradio on Ubuntu 22.04, runs it as a systemd service, and exposes it through Nginx with TLS.\n\nPrerequisites:a GPU-enabled Ubuntu 22.04 server, a domain A record (e.g.`gradio.example.com`\n\n), non-root sudo access, Nginx installed.\n\n**1. Install dependencies:**\n\n``` bash\n$ pip3 install realesrgan gfpgan basicsr gradio\n```\n\n`realesrgan`\n\n— background restoration`gfpgan`\n\n— face restoration`basicsr`\n\n— provides `RRDBNet`\n\n, the super-resolution architecture GFPGAN relies on`gradio`\n\n— the web interface**2. GFPGAN's pandas dependency needs jinja2 >= 3.1.2:**\n\n``` bash\n$ pip show jinja2\n```\n\nUpgrade if it's older:\n\n``` bash\n$ pip install --upgrade jinja2\n```\n\n**3. Create the project directory:**\n\n``` bash\n$ sudo mkdir -p /opt/gradio-webapp/\n$ sudo chown -R :$(id -gn) /opt/gradio-webapp/\n$ sudo chmod -R 775 /opt/gradio-webapp/\n```\n\nUploads a face image and returns two enhanced outputs.\n\n``` bash\n$ cd /opt/gradio-webapp/\n$ nano app.py\npython\nimport gradio as gr\nfrom gfpgan import GFPGANer\nfrom basicsr.archs.rrdbnet_arch import RRDBNet\nfrom realesrgan import RealESRGANer\nimport numpy as np\nimport cv2\nimport requests\n\ndef enhance_image(input_image):\n    arch = 'clean'\n    model_name = 'GFPGANv1.4'\n    gfpgan_checkpoint = 'https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth'\n    realersgan_checkpoint = 'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth'\n\n    rrdbnet = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)\n\n    bg_upsampler = RealESRGANer(\n        scale=2,\n        model_path=realersgan_checkpoint,\n        model=rrdbnet,\n        tile=400,\n        tile_pad=10,\n        pre_pad=0,\n        half=True\n    )\n\n    restorer = GFPGANer(\n        model_path=gfpgan_checkpoint,\n        upscale=2,\n        arch=arch,\n        channel_multiplier=2,\n        bg_upsampler=bg_upsampler\n    )\n\n    input_image = input_image.astype(np.uint8)\n    cropped_faces, restored_faces, restored_img = restorer.enhance(input_image)\n\n    return restored_faces[0], restored_img\n\ninterface = gr.Interface(\n    fn=enhance_image,\n    inputs=gr.Image(),\n    outputs=[gr.Image(), gr.Image()],\n    live=True,\n    title=\"Face Enhancement with GFPGAN\",\n    description=\"Upload an image of a face and see it enhanced using GFPGAN. Two outputs will be displayed: restored_faces and restored_img.\"\n)\n\ninterface.launch(server_name=\"0.0.0.0\", server_port=8080)\n```\n\n`enhance_image()`\n\nloads the GFPGAN/Real-ESRGAN checkpoints and runs restoration; `interface`\n\nwires that function to a Gradio UI listening on port 8080.\n\n**Test it:**\n\n``` bash\n$ python3 app.py\nRunning on local URL:  http://0.0.0.0:8080\n```\n\nSet `share=True`\n\nin `launch()`\n\nfor a temporary public Gradio link. Stop it with Ctrl+C once verified.\n\n``` bash\n$ sudo nano /etc/systemd/system/my_gradio_app.service\n```\n\nReplace `example-user`\n\nwith your actual account:\n\n```\n[Unit]\nDescription=My Gradio Web Application\n\n[Service]\nExecStart=/usr/bin/python3 /opt/gradio-webapp/app.py\nWorkingDirectory=/opt/gradio-webapp/\nRestart=always\nUser=example-user\nEnvironment=PATH=/usr/bin:/usr/local/bin\nEnvironment=PYTHONUNBUFFERED=1\n\n[Install]\nWantedBy=multi-user.target\nbash\n$ sudo systemctl daemon-reload\n$ sudo systemctl enable my_gradio_app\n$ sudo systemctl start my_gradio_app\n$ sudo systemctl status my_gradio_app\nbash\n$ sudo nano /etc/nginx/sites-available/gradio.conf\nserver {\n    listen 80;\n    listen [::]:80;\n    server_name gradio.example.com;\n\n    location / {\n        proxy_pass http://127.0.0.1:8080/;\n    }\n}\nbash\n$ sudo ln -s /etc/nginx/sites-available/gradio.conf /etc/nginx/sites-enabled/\n$ sudo nginx -t\n$ sudo systemctl restart nginx\nbash\n$ sudo ufw status\n$ sudo ufw allow 80/tcp\n$ sudo ufw allow 443/tcp\n$ sudo ufw reload\n$ sudo apt install -y certbot python3-certbot-nginx\n$ sudo certbot --nginx -d gradio.example.com -m admin@example.com --agree-tos\n$ sudo certbot renew --dry-run\n```\n\nVisit `https://gradio.example.com`\n\n, upload a sample face image, and confirm you get back the restored face crop and the full restored image.\n\nThe Gradio app is running as a managed systemd service behind Nginx with TLS. From here:\n\n`interface.launch()`\n\npattern works for any function-wrapped model`interface.launch(auth=...)`\n\n) if the app shouldn't be fully publicFor the full guide, visit the original article on ** Vultr Docs**.", "url": "https://wpnews.pro/news/deploying-gradio-on-ubuntu-22-04", "canonical_source": "https://dev.to/vultr/deploying-gradio-on-ubuntu-2204-gol", "published_at": "2026-07-31 12:39:57+00:00", "updated_at": "2026-07-31 13:04:13.226662+00:00", "lang": "en", "topics": ["developer-tools", "machine-learning", "artificial-intelligence"], "entities": ["Gradio", "GFPGAN", "Real-ESRGAN", "Ubuntu 22.04", "Nginx", "systemd", "TencentARC", "xinntao"], "alternates": {"html": "https://wpnews.pro/news/deploying-gradio-on-ubuntu-22-04", "markdown": "https://wpnews.pro/news/deploying-gradio-on-ubuntu-22-04.md", "text": "https://wpnews.pro/news/deploying-gradio-on-ubuntu-22-04.txt", "jsonld": "https://wpnews.pro/news/deploying-gradio-on-ubuntu-22-04.jsonld"}}