Download app.py from javadib/Tryit: direct link, hf CLI and curl.
- Browser
- Download file 734 Bytes
-
https://huggingface.co/spaces/javadib/Tryit/resolve/main/app.py
- Command line
-
hf download hf://spaces/javadib/Tryit/app.py
-
curl -L -o app.py https://huggingface.co/spaces/javadib/Tryit/resolve/main/app.py
734 Bytes
| import gradio as gr | |
| import requests | |
| from PIL import Image | |
| import os | |
| import shutil | |
| # اطمینان از وجود پوشه temp | |
| if not os.path.exists('temp'): | |
| os.makedirs('temp') | |
| def tryon(image): | |
| # ذخیره تصویر دریافتی | |
| image.save("temp/upload.jpg") | |
| # ارسال تصویر به API پردازش | |
| files = {'image': open("temp/upload.jpg", "rb")} | |
| response = requests.post("http://localhost:7860/upload/", files=files) | |
| if response.ok: | |
| result_path = f"temp/{response.json()['file']}" | |
| return Image.open(result_path) | |
| else: | |
| return "خطا در پردازش" | |
| # رابط کاربری Gradio | |
| demo = gr.Interface(fn=tryon, inputs="image", outputs="image") | |
| demo.launch() |