Spaces:
Sleeping
Sleeping
Download app.py from ssaeeeeed/my-image-proxy: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/spaces/ssaeeeeed/my-image-proxy/resolve/main/app.py
- Command line
-
hf download hf://spaces/ssaeeeeed/my-image-proxy/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ssaeeeeed/my-image-proxy/resolve/main/app.py
2.36 kB
| import gradio as gr | |
| import requests | |
| import os | |
| import io | |
| from PIL import Image | |
| from deep_translator import GoogleTranslator | |
| # توکن هاگینگ فیس شما (تنها چیزی که نیاز داری) | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| # مطمئن شو که این خط داخل آکولاد { } قرار دارد | |
| IMAGE_MODELS = { | |
| "Flux.1 Schnell": "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell" | |
| } | |
| def gemini_style_gen(user_input): | |
| if not user_input: | |
| return None, "لطفاً چیزی بنویسید..." | |
| try: | |
| # ۱. ترجمه خودکار (مثل جمینی که همه زبانها را میفهمد) | |
| translated = GoogleTranslator(source='auto', target='en').translate(user_input) | |
| # ۲. ارسال مستقیم به قویترین مدل رایگان فعلی | |
| headers = {"Authorization": f"Bearer {HF_TOKEN}"} | |
| response = requests.post(MODEL_URL, headers=headers, json={"inputs": translated}, timeout=60) | |
| if response.status_code == 200: | |
| return Image.open(io.BytesIO(response.content)), "✨ تصویر با موفقیت تولید شد." | |
| else: | |
| return None, f"خطا در ارتباط: {response.status_code}" | |
| except Exception as e: | |
| return None, f"خطای سیستم: {str(e)}" | |
| # طراحی محیط ساده و شیک (شبیه به چت جمینی) | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# 🍌 Nano-Interface (Powered by Qwen Logic)") | |
| gr.Markdown("بدون نیاز به API گوگل، مستقیماً تصویر بسازید.") | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_text = gr.Textbox( | |
| label="از من بخواه هر تصویری که دوست داری بسازم...", | |
| placeholder="مثلاً: یک موز فضایی با عینک آفتابی", | |
| lines=3 | |
| ) | |
| submit_btn = gr.Button("تولید تصویر (Gemini Mode)", variant="primary") | |
| with gr.Column(): | |
| output_img = gr.Image(label="نتیجه خروجی") | |
| status_msg = gr.Textbox(label="وضعیت", interactive=False) | |
| submit_btn.click(fn=gemini_style_gen, inputs=input_text, outputs=[output_img, status_msg]) | |
| demo.launch() |