banyapon commited on
Commit
32d7a9b
·
1 Parent(s): ce59718

fixed again app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -9,11 +9,9 @@ from gradio_pannellum import Pannellum
9
  import io
10
  from huggingface_hub import snapshot_download
11
  from txt2panoimg import Text2360PanoramaImagePipeline
12
- from transformers import utils
13
 
14
 
15
  # Download the model
16
- utils.move_cache()
17
  model_path = snapshot_download("archerfmy0831/sd-t2i-360panoimage")
18
 
19
  # Initialize pipelines
@@ -24,11 +22,12 @@ def text_to_pano(prompt, upscale):
24
  try:
25
  input_data = {'prompt': prompt, 'upscale': upscale, 'refinement': False}
26
  output = txt2panoimg(input_data)
27
- return output, output
28
  except Exception as e:
29
  print(f"Error generating panorama: {e}")
30
  return None, None
31
 
 
32
  title = """
33
  <div style="text-align: center;">
34
  <img src="https://ant.dpu.ac.th/wp-content/uploads/2024/04/dpulogo.png" width="200"/>
@@ -60,9 +59,11 @@ def create_aframe_html(image):
60
  """
61
  return aframe_html
62
 
 
63
  def create_aframe_preview(image):
64
- if image is None: # Handle case where image generation failed
65
  return gr.HTML("Error generating image. Please check the prompt or try again.")
 
66
  buffered = io.BytesIO()
67
  image.save(buffered, format="JPEG")
68
  img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
@@ -75,9 +76,10 @@ def create_aframe_preview(image):
75
  """
76
  return gr.HTML(f'<iframe srcdoc="{aframe_html}" allowfullscreen frameborder="0"></iframe>')
77
 
 
78
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
79
  gr.HTML(title)
80
-
81
  with gr.Row():
82
  with gr.Column():
83
  t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
@@ -96,20 +98,17 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
96
 
97
  def generate_with_update(prompt, upscale, trigger):
98
  output, image = text_to_pano(prompt, upscale)
99
- if image is not None: # Only create HTML if image generation succeeded
100
- html = create_aframe_html(image)
101
- else:
102
- html = "Failed to generate A-Frame HTML. Please try again."
103
- return output, image, html, create_aframe_preview(image), trigger + 1
104
 
105
  t2p_generate.click(
106
  generate_with_update,
107
  inputs=[t2p_input, t2p_upscale, update_trigger],
108
  outputs=[t2p_output, t2p_image_output, output_html, aframe_preview, update_trigger]
109
  )
110
- output_image.change(create_aframe_preview, inputs=[output_image], outputs=[aframe_preview])
111
-
112
-
113
  copy_html_button.click(
114
  None,
115
  inputs=[output_html],
 
9
  import io
10
  from huggingface_hub import snapshot_download
11
  from txt2panoimg import Text2360PanoramaImagePipeline
 
12
 
13
 
14
  # Download the model
 
15
  model_path = snapshot_download("archerfmy0831/sd-t2i-360panoimage")
16
 
17
  # Initialize pipelines
 
22
  try:
23
  input_data = {'prompt': prompt, 'upscale': upscale, 'refinement': False}
24
  output = txt2panoimg(input_data)
25
+ return output, output
26
  except Exception as e:
27
  print(f"Error generating panorama: {e}")
28
  return None, None
29
 
30
+
31
  title = """
32
  <div style="text-align: center;">
33
  <img src="https://ant.dpu.ac.th/wp-content/uploads/2024/04/dpulogo.png" width="200"/>
 
59
  """
60
  return aframe_html
61
 
62
+
63
  def create_aframe_preview(image):
64
+ if image is None:
65
  return gr.HTML("Error generating image. Please check the prompt or try again.")
66
+
67
  buffered = io.BytesIO()
68
  image.save(buffered, format="JPEG")
69
  img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
 
76
  """
77
  return gr.HTML(f'<iframe srcdoc="{aframe_html}" allowfullscreen frameborder="0"></iframe>')
78
 
79
+
80
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
81
  gr.HTML(title)
82
+
83
  with gr.Row():
84
  with gr.Column():
85
  t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
 
98
 
99
  def generate_with_update(prompt, upscale, trigger):
100
  output, image = text_to_pano(prompt, upscale)
101
+ html = create_aframe_html(image) if image is not None else "Failed to generate A-Frame HTML. Please try again."
102
+ preview = create_aframe_preview(image)
103
+ return output, image, html, preview, trigger + 1
 
 
104
 
105
  t2p_generate.click(
106
  generate_with_update,
107
  inputs=[t2p_input, t2p_upscale, update_trigger],
108
  outputs=[t2p_output, t2p_image_output, output_html, aframe_preview, update_trigger]
109
  )
110
+ t2p_image_output.change(create_aframe_preview, inputs=[t2p_image_output], outputs=[aframe_preview])
111
+
 
112
  copy_html_button.click(
113
  None,
114
  inputs=[output_html],