Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines345678910111213141516171819202122232425262728293031325 unmodified lines38394041424344239 unmodified lines2842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343352 unmodified linesimport osfrom dotenv import load_dotenvimport warningsimport torch# Suppress warningswarnings.filterwarnings('ignore', category=UserWarning)# Load environment variablesload_dotenv()HF_TOKEN = os.getenv("HF_TOKEN")# Force CPU modeos.environ['CUDA_VISIBLE_DEVICES'] = ''if torch.cuda.is_available():device = torch.device('cuda')else:device = torch.device('cpu')def generate_diagram(prompt, width=1024, height=1024):"""Generate a diagram using FLUX AI"""try:client = Client("black-forest-labs/FLUX.1-schnell",hf_token=HF_TOKEN,cpu_only=True # Force CPU mode)result = client.predict(prompt,1872187377, # seed5 unmodified lines)return resultexcept Exception as e:raise gr.Error(f"Error generating diagram: {str(e)}")# Convert example format for GradioGRADIO_EXAMPLES = [239 unmodified linesfor example in EXAMPLES]# Create Gradio interfacedemo = gr.Interface(fn=generate_diagram,inputs=[gr.Textbox(label="Diagram Prompt",placeholder="Enter your diagram structure...",lines=10),gr.Slider(label="Width",minimum=512,maximum=2048,step=128,value=1024),gr.Slider(label="Height",minimum=512,maximum=2048,step=128,value=1024)],outputs=gr.Image(label="Generated Diagram"),title="๐จ FLUX Diagram Generator",description="Generate beautiful hand-drawn style diagrams using FLUX AI",article="""### Tips for Better Results- Use clear hierarchical structures- Include icon descriptions in brackets- Keep text concise and meaningful- Use consistent formatting""",examples=GRADIO_EXAMPLES,cache_examples=True)if __name__ == "__main__":try:demo.launch(server_name="0.0.0.0",server_port=7860,share=False,show_error=True,debug=True)except Exception as e:print(f"Error launching app: {str(e)}")2 unmodified lines345678910111213141516171819202122232425262728295 unmodified lines35363738394041239 unmodified lines2812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303312 unmodified linesimport osfrom dotenv import load_dotenvimport warnings# ๊ฒฝ๊ณ ๋ฉ์์ง ์จ๊ธฐ๊ธฐwarnings.filterwarnings('ignore', category=UserWarning)# ํ๊ฒฝ ๋ณ์ ๋ก๋load_dotenv()HF_TOKEN = os.getenv("HF_TOKEN")def generate_diagram(prompt, width=1024, height=1024):"""FLUX AI๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ด์ด๊ทธ๋จ ์์ฑ"""try:# API ํธ์ถ์ ํตํด ์ด๋ฏธ์ง ์์ฑresult = gr.Image.update(value=None) # ์ด๊ธฐ ์ํ๋ ๋น ์ด๋ฏธ์ง# Hugging Face API ํธ์ถclient = Client("https://black-forest-labs-flux-1-schnell.hf.space", # API ์๋ํฌ์ธํธ ์ง์ ์ง์ hf_token=HF_TOKEN,)# ์ด๋ฏธ์ง ์์ฑresult = client.predict(prompt,1872187377, # seed5 unmodified lines)return resultexcept Exception as e:raise gr.Error(f"๋ค์ด์ด๊ทธ๋จ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")# Convert example format for GradioGRADIO_EXAMPLES = [239 unmodified linesfor example in EXAMPLES]demo = gr.Interface(fn=generate_diagram,inputs=[gr.Textbox(label="๋ค์ด์ด๊ทธ๋จ ํ๋กฌํํธ",placeholder="๋ค์ด์ด๊ทธ๋จ ๊ตฌ์กฐ๋ฅผ ์ ๋ ฅํ์ธ์...",lines=10),gr.Slider(label="๋๋น",minimum=512,maximum=2048,step=128,value=1024),gr.Slider(label="๋์ด",minimum=512,maximum=2048,step=128,value=1024)],outputs=gr.Image(label="์์ฑ๋ ๋ค์ด์ด๊ทธ๋จ"),title="๐จ FLUX ๋ค์ด์ด๊ทธ๋จ ์์ฑ๊ธฐ",description="FLUX AI๋ฅผ ์ฌ์ฉํ์ฌ ์๋ฆ๋ค์ด ์๊ทธ๋ฆผ ์คํ์ผ์ ๋ค์ด์ด๊ทธ๋จ์ ์์ฑํฉ๋๋ค",article="""### ๋ ๋์ ๊ฒฐ๊ณผ๋ฅผ ์ํ ํ- ๋ช ํํ ๊ณ์ธต ๊ตฌ์กฐ ์ฌ์ฉ- ๋๊ดํธ ์์ ์์ด์ฝ ์ค๋ช ํฌํจ- ๊ฐ๊ฒฐํ๊ณ ์๋ฏธ ์๋ ํ ์คํธ ์ฌ์ฉ- ์ผ๊ด๋ ํ์ ์ ์ง""",examples=GRADIO_EXAMPLES,cache_examples=True)# ์ฑ ์คํif __name__ == "__main__":demo.launch(server_name="0.0.0.0",server_port=7860,share=False,show_error=True,debug=True,enable_queue=True # ํ ํ์ฑํ๋ก ์์ฒญ ๊ด๋ฆฌ)
app.py+33-37