akhaliq HF Staff commited on
Commit
1310976
·
1 Parent(s): 590a324

fix import for gradio and streamlit

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -7862,19 +7862,29 @@ with gr.Blocks(
7862
  status, code = load_project_from_url(url)
7863
  # Extract space info for deployment
7864
  is_valid, username, project_name = check_hf_space_url(url)
7865
- space_info = f"{username}/{project_name}" if is_valid else ""
7866
  loaded_history = [[f"Imported Space from {url}", code]]
7867
 
7868
  # Determine the correct language/framework based on the imported content
7869
  code_lang = "html" # default
7870
  framework_type = "html" # for language dropdown
7871
- if is_streamlit_code(code) or is_gradio_code(code):
 
 
 
 
 
7872
  code_lang = "python"
7873
  framework_type = "python"
7874
  elif "=== index.html ===" in code and "=== index.js ===" in code and "=== style.css ===" in code:
7875
  # This is a transformers.js app with the combined format
7876
  code_lang = "html" # Use html for code display
7877
  framework_type = "transformers.js" # But set dropdown to transformers.js
 
 
 
 
 
7878
 
7879
  # Return the updates with proper language settings
7880
  return [
 
7862
  status, code = load_project_from_url(url)
7863
  # Extract space info for deployment
7864
  is_valid, username, project_name = check_hf_space_url(url)
7865
+ space_name = f"{username}/{project_name}" if is_valid else ""
7866
  loaded_history = [[f"Imported Space from {url}", code]]
7867
 
7868
  # Determine the correct language/framework based on the imported content
7869
  code_lang = "html" # default
7870
  framework_type = "html" # for language dropdown
7871
+
7872
+ # Check imports to determine framework for Python code
7873
+ if is_streamlit_code(code):
7874
+ code_lang = "python"
7875
+ framework_type = "python"
7876
+ elif is_gradio_code(code):
7877
  code_lang = "python"
7878
  framework_type = "python"
7879
  elif "=== index.html ===" in code and "=== index.js ===" in code and "=== style.css ===" in code:
7880
  # This is a transformers.js app with the combined format
7881
  code_lang = "html" # Use html for code display
7882
  framework_type = "transformers.js" # But set dropdown to transformers.js
7883
+ elif ("import " in code or "def " in code) and not ("<!DOCTYPE html>" in code or "<html" in code):
7884
+ # This looks like Python code but doesn't match Streamlit/Gradio patterns
7885
+ # Default to Gradio for Python spaces
7886
+ code_lang = "python"
7887
+ framework_type = "gradio"
7888
 
7889
  # Return the updates with proper language settings
7890
  return [