jasonlawAI79 commited on
Commit
8094c6f
·
verified ·
1 Parent(s): 9e86500

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -26
app.py CHANGED
@@ -21,37 +21,51 @@ try:
21
  # Try to connect to your deployed Modal functions using the new API
22
  logger.info("🔄 Attempting to connect to Modal functions...")
23
 
24
- generate_content_with_llm = modal.Function.from_name(
25
- "content-creation-agent",
26
- "generate_content_with_llm"
27
- )
28
-
29
- # Test connection with health check
30
- health_check_func = modal.Function.from_name(
31
- "content-creation-agent",
32
- "health_check"
33
- )
34
-
35
- # Test if Modal is working
36
- test_result = health_check_func.remote()
37
- logger.info(f"✅ Modal health check passed: {test_result}")
38
-
39
- MODAL_AVAILABLE = True
40
- logger.info("✅ Modal successfully connected")
41
-
42
- except Exception as e:
43
- logger.warning(f"⚠️ Modal main function connection failed: {e}")
44
- # Try fallback function instead
45
  try:
46
  generate_content_with_llm = modal.Function.from_name(
47
  "content-creation-agent",
48
- "generate_fallback_content"
49
  )
 
 
 
 
 
 
 
 
 
 
 
50
  MODAL_AVAILABLE = True
51
- logger.info("✅ Modal connected using fallback function")
52
- except Exception as e2:
53
- logger.warning(f"⚠️ Modal fallback also failed: {e2}")
54
- MODAL_AVAILABLE = False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  else:
56
  logger.warning("⚠️ MODAL_TOKEN not found in environment variables")
57
  logger.info("💡 To fix this, add MODAL_TOKEN to your HuggingFace Space environment variables")
 
21
  # Try to connect to your deployed Modal functions using the new API
22
  logger.info("🔄 Attempting to connect to Modal functions...")
23
 
24
+ # First try the main AI function
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  try:
26
  generate_content_with_llm = modal.Function.from_name(
27
  "content-creation-agent",
28
+ "generate_content_with_llm"
29
  )
30
+
31
+ # Test connection with health check
32
+ health_check_func = modal.Function.from_name(
33
+ "content-creation-agent",
34
+ "health_check"
35
+ )
36
+
37
+ # Test if Modal is working
38
+ test_result = health_check_func.remote()
39
+ logger.info(f"✅ Modal health check passed: {test_result}")
40
+
41
  MODAL_AVAILABLE = True
42
+ logger.info("✅ Modal successfully connected to main AI function")
43
+
44
+ except Exception as e:
45
+ logger.warning(f"⚠️ Modal main function connection failed: {e}")
46
+ # Try fallback function instead (this one we know works)
47
+ try:
48
+ generate_content_with_llm = modal.Function.from_name(
49
+ "content-creation-agent",
50
+ "generate_fallback_content"
51
+ )
52
+
53
+ # Still test health check
54
+ health_check_func = modal.Function.from_name(
55
+ "content-creation-agent",
56
+ "health_check"
57
+ )
58
+ test_result = health_check_func.remote()
59
+ logger.info(f"✅ Modal health check passed: {test_result}")
60
+
61
+ MODAL_AVAILABLE = True
62
+ logger.info("✅ Modal connected using fallback function (still high quality!)")
63
+ except Exception as e2:
64
+ logger.warning(f"⚠️ Modal fallback also failed: {e2}")
65
+ MODAL_AVAILABLE = False
66
+ except Exception as main_e:
67
+ logger.warning(f"⚠️ Modal connection failed: {main_e}")
68
+ MODAL_AVAILABLE = False
69
  else:
70
  logger.warning("⚠️ MODAL_TOKEN not found in environment variables")
71
  logger.info("💡 To fix this, add MODAL_TOKEN to your HuggingFace Space environment variables")