skallewag commited on
Commit
4471dc6
·
verified ·
1 Parent(s): 8f6c6df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -7
app.py CHANGED
@@ -5,6 +5,7 @@ import tempfile
5
  import logging
6
  import shutil
7
  import requests
 
8
 
9
  # Configure logging
10
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
@@ -16,18 +17,26 @@ if not hf_token:
16
  logger.warning("HF_TOKEN environment variable not set. Connections to private spaces will fail.")
17
  logger.warning("Please set the HF_TOKEN environment variable with your Hugging Face token.")
18
 
19
- # Create the client with explicit authentication - update this to your private space
20
  BACKEND_SPACE = "skallewag/prepperoni-backend"
21
- client = Client(
22
- BACKEND_SPACE, # Your private Space name
23
- hf_token=hf_token # Your Hugging Face token
24
- )
25
 
26
- # Try to connect and list endpoints
 
 
 
 
27
  try:
28
- logger.info(f"Available endpoints: {client.endpoints}")
 
 
 
 
 
 
29
  except Exception as e:
 
30
  logger.error(f"Error connecting to backend space '{BACKEND_SPACE}': {str(e)}")
 
31
 
32
  # Create a simple interface that forwards to your private Space
33
  with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter") as app:
@@ -35,6 +44,21 @@ with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter") as app:
35
  gr.Markdown("# Prepperoni 🍕")
36
  gr.Markdown("Convert Adobe Premiere Pro project files to XML format for use in other video editing software.")
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  with gr.Row():
39
  with gr.Column(scale=1):
40
  # Input components
@@ -77,6 +101,9 @@ with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter") as app:
77
  # Function to process the file through the backend
78
  def process_file(file, sequence_name):
79
  try:
 
 
 
80
  if file is None:
81
  return None, "Error: No file provided", "Please upload a Premiere Pro project file."
82
 
@@ -152,6 +179,17 @@ with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter") as app:
152
  outputs=[output_file, output_message, status]
153
  )
154
 
 
 
 
 
 
 
 
 
 
 
 
155
  # Launch the app
156
  if __name__ == "__main__":
157
  app.launch(show_error=True)
 
5
  import logging
6
  import shutil
7
  import requests
8
+ from huggingface_hub.utils import RepositoryNotFoundError
9
 
10
  # Configure logging
11
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 
17
  logger.warning("HF_TOKEN environment variable not set. Connections to private spaces will fail.")
18
  logger.warning("Please set the HF_TOKEN environment variable with your Hugging Face token.")
19
 
20
+ # Backend space name - update this to your private space
21
  BACKEND_SPACE = "skallewag/prepperoni-backend"
 
 
 
 
22
 
23
+ # Initialize client as None first
24
+ client = None
25
+ connection_error = None
26
+
27
+ # Try to initialize the client
28
  try:
29
+ client = Client(
30
+ BACKEND_SPACE,
31
+ hf_token=hf_token
32
+ )
33
+ # Check available endpoints
34
+ endpoints = client.endpoints
35
+ logger.info(f"Successfully connected to backend. Available endpoints: {endpoints}")
36
  except Exception as e:
37
+ connection_error = str(e)
38
  logger.error(f"Error connecting to backend space '{BACKEND_SPACE}': {str(e)}")
39
+ logger.error("This might be due to a missing or invalid HF_TOKEN, or the backend space may be offline or private.")
40
 
41
  # Create a simple interface that forwards to your private Space
42
  with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter") as app:
 
44
  gr.Markdown("# Prepperoni 🍕")
45
  gr.Markdown("Convert Adobe Premiere Pro project files to XML format for use in other video editing software.")
46
 
47
+ # Display a warning if there's a connection error
48
+ if connection_error:
49
+ gr.Markdown(f"""
50
+ ⚠️ **Warning: Cannot connect to backend service**
51
+
52
+ There was an error connecting to the processing backend. The app may not function correctly.
53
+
54
+ Error details: {connection_error}
55
+
56
+ If you're the administrator, please make sure:
57
+ 1. The HF_TOKEN environment variable is set correctly in Space settings
58
+ 2. The backend space name is correct (currently set to: {BACKEND_SPACE})
59
+ 3. The backend space is running and accessible
60
+ """, elem_classes=["error-box"])
61
+
62
  with gr.Row():
63
  with gr.Column(scale=1):
64
  # Input components
 
101
  # Function to process the file through the backend
102
  def process_file(file, sequence_name):
103
  try:
104
+ if not client:
105
+ return None, "Error: Cannot connect to backend service. Please check the connection error at the top of the page.", "Configuration Error"
106
+
107
  if file is None:
108
  return None, "Error: No file provided", "Please upload a Premiere Pro project file."
109
 
 
179
  outputs=[output_file, output_message, status]
180
  )
181
 
182
+ # Add custom CSS for error box
183
+ app.load(css="""
184
+ .error-box {
185
+ background-color: #ffebe9;
186
+ border: 1px solid #e9484d;
187
+ padding: 16px;
188
+ border-radius: 8px;
189
+ margin-bottom: 20px;
190
+ }
191
+ """)
192
+
193
  # Launch the app
194
  if __name__ == "__main__":
195
  app.launch(show_error=True)