meissosisai commited on
Commit
3e10159
·
1 Parent(s): 9e2257b

Fix: Resolve Gradio 6.0 compatibility and gr.Div attribute error

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -2,10 +2,8 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
  from PIL import Image
5
- import io
6
 
7
  # Initialize the HF Inference Client
8
- # It will use the HF_TOKEN from your Space's environment variables
9
  client = InferenceClient(token=os.getenv("HF_TOKEN"))
10
 
11
  MODELS = {
@@ -19,30 +17,24 @@ def generate_image(prompt, model_choice):
19
 
20
  model_id = MODELS.get(model_choice, MODELS["Flux.1 [Schnell]"])
21
 
22
- print(f"[Vision] Request: {prompt[:50]}... via {model_choice}")
23
-
24
  try:
25
- # Use the inference client to get an image
26
- # This returns a PIL.Image object directly
27
  image = client.text_to_image(prompt, model=model_id)
28
  return image
29
  except Exception as e:
30
- print(f"[Error] Generation failed: {str(e)}")
31
- # Raise error to show in Gradio UI
32
  raise gr.Error(f"Neural Core Error: {str(e)}")
33
 
34
  # UI Styling
35
  custom_css = """
36
  footer {visibility: hidden}
37
- .gradio-container { background-color: #030303 !important; }
38
- #title-container { text-align: center; margin-bottom: 20px; }
39
  #gen-button { background: #ffffff !important; color: #000000 !important; font-weight: 900 !important; }
40
  """
41
 
42
- with gr.Blocks(css=custom_css, theme=gr.themes.Default(primary_hue="zinc", secondary_hue="zinc")) as demo:
43
- with gr.Div(elem_id="title-container"):
44
- gr.Markdown("# CODEX_VISION")
45
- gr.Markdown("NEURAL PROJECTION INTERFACE")
46
 
47
  with gr.Row():
48
  with gr.Column(scale=1):
@@ -68,4 +60,8 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default(primary_hue="zinc", secon
68
  )
69
 
70
  if __name__ == "__main__":
71
- demo.queue().launch()
 
 
 
 
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
  from PIL import Image
 
5
 
6
  # Initialize the HF Inference Client
 
7
  client = InferenceClient(token=os.getenv("HF_TOKEN"))
8
 
9
  MODELS = {
 
17
 
18
  model_id = MODELS.get(model_choice, MODELS["Flux.1 [Schnell]"])
19
 
 
 
20
  try:
 
 
21
  image = client.text_to_image(prompt, model=model_id)
22
  return image
23
  except Exception as e:
 
 
24
  raise gr.Error(f"Neural Core Error: {str(e)}")
25
 
26
  # UI Styling
27
  custom_css = """
28
  footer {visibility: hidden}
29
+ body { background-color: #030303 !important; }
30
+ .gradio-container { border: none !important; }
31
  #gen-button { background: #ffffff !important; color: #000000 !important; font-weight: 900 !important; }
32
  """
33
 
34
+ # Fixed: Removed gr.Div (unsupported) and moved theme/css to launch() for Gradio 6 compatibility
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("# CODEX_VISION", elem_id="title")
37
+ gr.Markdown("### NEURAL PROJECTION INTERFACE")
38
 
39
  with gr.Row():
40
  with gr.Column(scale=1):
 
60
  )
61
 
62
  if __name__ == "__main__":
63
+ # Gradio 6.0 compatible launch
64
+ demo.queue().launch(
65
+ css=custom_css,
66
+ theme=gr.themes.Default(primary_hue="zinc", secondary_hue="zinc")
67
+ )