Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import gradio as gr
|
|
| 6 |
logging.basicConfig(level=logging.INFO)
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
| 9 |
-
#
|
| 10 |
MODAL_AVAILABLE = False
|
| 11 |
generate_content_with_llm = None
|
| 12 |
|
|
@@ -14,17 +14,23 @@ try:
|
|
| 14 |
import modal
|
| 15 |
logger.info(f"Modal version: {modal.__version__}")
|
| 16 |
|
| 17 |
-
# Check for Modal token
|
| 18 |
-
|
|
|
|
| 19 |
try:
|
| 20 |
-
#
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
"content-creation-agent",
|
| 23 |
"generate_content_with_llm"
|
| 24 |
)
|
| 25 |
|
| 26 |
# Test connection with health check
|
| 27 |
-
health_check_func = modal.Function.
|
| 28 |
"content-creation-agent",
|
| 29 |
"health_check"
|
| 30 |
)
|
|
@@ -37,10 +43,10 @@ try:
|
|
| 37 |
logger.info("✅ Modal successfully connected")
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
-
logger.warning(f"⚠️ Modal connection failed: {e}")
|
| 41 |
# Try fallback function instead
|
| 42 |
try:
|
| 43 |
-
generate_content_with_llm = modal.Function.
|
| 44 |
"content-creation-agent",
|
| 45 |
"generate_fallback_content"
|
| 46 |
)
|
|
@@ -48,11 +54,14 @@ try:
|
|
| 48 |
logger.info("✅ Modal connected using fallback function")
|
| 49 |
except Exception as e2:
|
| 50 |
logger.warning(f"⚠️ Modal fallback also failed: {e2}")
|
|
|
|
| 51 |
else:
|
| 52 |
-
logger.warning("⚠️ MODAL_TOKEN not found in environment")
|
| 53 |
|
| 54 |
except ImportError:
|
| 55 |
logger.warning("⚠️ Modal package not available")
|
|
|
|
|
|
|
| 56 |
|
| 57 |
logger.info(f"Modal Status: {'✅ Available' if MODAL_AVAILABLE else '❌ Unavailable'}")
|
| 58 |
|
|
|
|
| 6 |
logging.basicConfig(level=logging.INFO)
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
| 9 |
+
# Modal setup with proper secret handling
|
| 10 |
MODAL_AVAILABLE = False
|
| 11 |
generate_content_with_llm = None
|
| 12 |
|
|
|
|
| 14 |
import modal
|
| 15 |
logger.info(f"Modal version: {modal.__version__}")
|
| 16 |
|
| 17 |
+
# Check for Modal token - this should be set in HuggingFace environment
|
| 18 |
+
modal_token = os.environ.get("MODAL_TOKEN")
|
| 19 |
+
if modal_token:
|
| 20 |
try:
|
| 21 |
+
# Set up Modal client with token
|
| 22 |
+
os.environ["MODAL_TOKEN"] = modal_token
|
| 23 |
+
|
| 24 |
+
# Try to connect to your deployed Modal functions
|
| 25 |
+
logger.info("🔄 Attempting to connect to Modal functions...")
|
| 26 |
+
|
| 27 |
+
generate_content_with_llm = modal.Function.lookup(
|
| 28 |
"content-creation-agent",
|
| 29 |
"generate_content_with_llm"
|
| 30 |
)
|
| 31 |
|
| 32 |
# Test connection with health check
|
| 33 |
+
health_check_func = modal.Function.lookup(
|
| 34 |
"content-creation-agent",
|
| 35 |
"health_check"
|
| 36 |
)
|
|
|
|
| 43 |
logger.info("✅ Modal successfully connected")
|
| 44 |
|
| 45 |
except Exception as e:
|
| 46 |
+
logger.warning(f"⚠️ Modal main function connection failed: {e}")
|
| 47 |
# Try fallback function instead
|
| 48 |
try:
|
| 49 |
+
generate_content_with_llm = modal.Function.lookup(
|
| 50 |
"content-creation-agent",
|
| 51 |
"generate_fallback_content"
|
| 52 |
)
|
|
|
|
| 54 |
logger.info("✅ Modal connected using fallback function")
|
| 55 |
except Exception as e2:
|
| 56 |
logger.warning(f"⚠️ Modal fallback also failed: {e2}")
|
| 57 |
+
MODAL_AVAILABLE = False
|
| 58 |
else:
|
| 59 |
+
logger.warning("⚠️ MODAL_TOKEN not found in environment variables")
|
| 60 |
|
| 61 |
except ImportError:
|
| 62 |
logger.warning("⚠️ Modal package not available")
|
| 63 |
+
except Exception as e:
|
| 64 |
+
logger.warning(f"⚠️ Modal setup failed: {e}")
|
| 65 |
|
| 66 |
logger.info(f"Modal Status: {'✅ Available' if MODAL_AVAILABLE else '❌ Unavailable'}")
|
| 67 |
|