junelam1201 commited on
Commit
53fbbbf
Β·
verified Β·
1 Parent(s): e1d1678

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -43,15 +43,19 @@ def create_building_analysis(input_image):
43
  except Exception as e:
44
  return create_info_image(f"Analysis error: {str(e)}")
45
 
 
 
46
  def test_huggingface_api():
47
- """Test if Hugging Face API is working"""
48
  if not HF_TOKEN:
49
  return False, "No HF_TOKEN found in environment variables"
50
 
51
- # Test with a simple model
52
  API_URL = "https://api-inference.huggingface.co/models/google/vit-base-patch16-224"
53
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
54
- payload = {"inputs": "Hello"}
 
 
55
 
56
  try:
57
  response = requests.post(API_URL, headers=headers, json=payload, timeout=10)
@@ -62,6 +66,7 @@ def test_huggingface_api():
62
  except Exception as e:
63
  return False, f"❌ API test error: {str(e)}"
64
 
 
65
  def generate_architectural_remix(original_image, style_choice):
66
  """Main pipeline"""
67
  if original_image is None:
@@ -101,6 +106,7 @@ def generate_architectural_remix(original_image, style_choice):
101
  status = f"❌ Pipeline error: {str(e)}"
102
  return building_analysis, status, error_img
103
 
 
104
  def generate_with_api(style_name):
105
  """Try to generate image via API"""
106
  if not HF_TOKEN:
@@ -141,6 +147,7 @@ def generate_with_api(style_name):
141
  print(f"❌ Request error: {str(e)}")
142
  return None
143
 
 
144
  def create_demo_building(style_name):
145
  """Create a beautiful demo building"""
146
  # Style-based color schemes
@@ -210,6 +217,7 @@ def create_demo_building(style_name):
210
 
211
  return img
212
 
 
213
  def create_info_image(message):
214
  """Create informational image"""
215
  img = Image.new('RGB', (512, 512), color='#2C3E50')
@@ -239,6 +247,7 @@ def create_info_image(message):
239
 
240
  return img
241
 
 
242
  # Create Gradio interface
243
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
244
  gr.Markdown("""
@@ -323,4 +332,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
323
  """)
324
 
325
  if __name__ == "__main__":
326
- demo.launch(debug=True)
 
43
  except Exception as e:
44
  return create_info_image(f"Analysis error: {str(e)}")
45
 
46
+
47
+ # βœ… FIXED FUNCTION
48
  def test_huggingface_api():
49
+ """Test if Hugging Face API is working correctly"""
50
  if not HF_TOKEN:
51
  return False, "No HF_TOKEN found in environment variables"
52
 
53
+ # Use an image model for testing
54
  API_URL = "https://api-inference.huggingface.co/models/google/vit-base-patch16-224"
55
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
56
+
57
+ # βœ… Use a valid image URL instead of a text string
58
+ payload = {"inputs": "https://huggingface.co/front/assets/huggingface_logo-noborder.svg"}
59
 
60
  try:
61
  response = requests.post(API_URL, headers=headers, json=payload, timeout=10)
 
66
  except Exception as e:
67
  return False, f"❌ API test error: {str(e)}"
68
 
69
+
70
  def generate_architectural_remix(original_image, style_choice):
71
  """Main pipeline"""
72
  if original_image is None:
 
106
  status = f"❌ Pipeline error: {str(e)}"
107
  return building_analysis, status, error_img
108
 
109
+
110
  def generate_with_api(style_name):
111
  """Try to generate image via API"""
112
  if not HF_TOKEN:
 
147
  print(f"❌ Request error: {str(e)}")
148
  return None
149
 
150
+
151
  def create_demo_building(style_name):
152
  """Create a beautiful demo building"""
153
  # Style-based color schemes
 
217
 
218
  return img
219
 
220
+
221
  def create_info_image(message):
222
  """Create informational image"""
223
  img = Image.new('RGB', (512, 512), color='#2C3E50')
 
247
 
248
  return img
249
 
250
+
251
  # Create Gradio interface
252
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
253
  gr.Markdown("""
 
332
  """)
333
 
334
  if __name__ == "__main__":
335
+ demo.launch(debug=True)