aiqcamp commited on
Commit
504dc98
·
verified ·
1 Parent(s): d7f82cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -3,6 +3,7 @@ from gradio_client import Client
3
  import os
4
  from dotenv import load_dotenv
5
  import warnings
 
6
 
7
  # Suppress warnings
8
  warnings.filterwarnings('ignore', category=UserWarning)
@@ -11,12 +12,20 @@ warnings.filterwarnings('ignore', category=UserWarning)
11
  load_dotenv()
12
  HF_TOKEN = os.getenv("HF_TOKEN")
13
 
 
 
 
 
 
 
 
14
  def generate_diagram(prompt, width=1024, height=1024):
15
  """Generate a diagram using FLUX AI"""
16
  try:
17
  client = Client(
18
  "black-forest-labs/FLUX.1-schnell",
19
  hf_token=HF_TOKEN,
 
20
  )
21
  result = client.predict(
22
  prompt,
@@ -313,12 +322,14 @@ demo = gr.Interface(
313
  cache_examples=True
314
  )
315
 
316
- # Launch app
317
  if __name__ == "__main__":
318
- demo.launch(
319
- server_name="0.0.0.0",
320
- server_port=7860,
321
- share=False,
322
- show_error=True,
323
- debug=True
324
- )
 
 
 
 
3
  import os
4
  from dotenv import load_dotenv
5
  import warnings
6
+ import torch
7
 
8
  # Suppress warnings
9
  warnings.filterwarnings('ignore', category=UserWarning)
 
12
  load_dotenv()
13
  HF_TOKEN = os.getenv("HF_TOKEN")
14
 
15
+ # Force CPU mode
16
+ os.environ['CUDA_VISIBLE_DEVICES'] = ''
17
+ if torch.cuda.is_available():
18
+ device = torch.device('cuda')
19
+ else:
20
+ device = torch.device('cpu')
21
+
22
  def generate_diagram(prompt, width=1024, height=1024):
23
  """Generate a diagram using FLUX AI"""
24
  try:
25
  client = Client(
26
  "black-forest-labs/FLUX.1-schnell",
27
  hf_token=HF_TOKEN,
28
+ cpu_only=True # Force CPU mode
29
  )
30
  result = client.predict(
31
  prompt,
 
322
  cache_examples=True
323
  )
324
 
 
325
  if __name__ == "__main__":
326
+ try:
327
+ demo.launch(
328
+ server_name="0.0.0.0",
329
+ server_port=7860,
330
+ share=False,
331
+ show_error=True,
332
+ debug=True
333
+ )
334
+ except Exception as e:
335
+ print(f"Error launching app: {str(e)}")