update
Browse files7 unmodified lines891011121314151112137 unmodified linesapp_file: app.pypinned: falsedisable_embedding: truehf_oauth: truehf_oauth_scopes: - read-repos - write-repos - manage-repos---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference17 unmodified lines1819202121222324389 unmodified lines414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598417418419490 unmodified lines91091191210951096109710981099110091391411031104110591591691760 unmodified lines9789799801172117311741175117611771178117911801181118298198298343 unmodified lines102710281029123212331234123512361237123812391240124112421243124410301031103217 unmodified linesimport time
import gradio as grfrom huggingface_hub import InferenceClient, HfApi, create_repo, whoamifrom huggingface_hub import InferenceClientfrom tavily import TavilyClient
# Configuration389 unmodified lines # Return the first demo description as fallback return DEMO_LIST[0]['description']
def get_user_info(profile: gr.OAuthProfile | None) -> str: """Get user information from OAuth profile""" if profile is None: return "π€ **Guest User**\n*Sign in to personalize your experience*" return f"π€ **{profile.name}**\n*Welcome back!*"
def create_space_from_code(html_code: str, title: str, oauth_token: gr.OAuthToken | None) -> str: """Create a new Hugging Face Space with the generated HTML code""" if not oauth_token: return "β **Error:** Please sign in with your Hugging Face account to deploy spaces." if not html_code or not html_code.strip(): return "β **Error:** No code to deploy. Please generate some code first." if not title or not title.strip(): return "β **Error:** Please provide a title for your space." try: # Clean up the title for use as repo name import re clean_title = re.sub(r'[^a-zA-Z0-9\s-]', '', title) clean_title = re.sub(r'\s+', '-', clean_title).lower() clean_title = clean_title[:50] # Limit length # Get user info to create repo under their account user_info = whoami(oauth_token.token) username = user_info.get('name', 'unknown') # Create unique repo ID import time timestamp = int(time.time()) repo_id = f"{username}/{clean_title}-{timestamp}" # Create the space api = HfApi(token=oauth_token.token) api.create_repo( repo_id=repo_id, repo_type="space", space_sdk="static", space_hardware="cpu-basic" ) # Create the HTML file content html_content = f"""<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>{title}</title> <style> body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; }} .container {{ max-width: 1200px; margin: 0 auto; background: white; border-radius: 12px; box-shadow: 0 20px 40px rgba(0,0,0,0.1); overflow: hidden; }} .header {{ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 30px; text-align: center; }} .header h1 {{ margin: 0; font-size: 2.5em; font-weight: 300; }} .header p {{ margin: 10px 0 0 0; opacity: 0.9; font-size: 1.1em; }} .content {{ padding: 40px; }} .footer {{ background: #f8f9fa; padding: 20px; text-align: center; color: #666; border-top: 1px solid #eee; }} .footer a {{ color: #667eea; text-decoration: none; }} .footer a:hover {{ text-decoration: underline; }} </style></head><body> <div class="container"> <div class="header"> <h1>{title}</h1> <p>Generated with AnyCoder - AI-Powered Code Generator</p> </div> <div class="content"> {html_code} </div> <div class="footer"> <p>π Created with <a href="https://huggingface.co/spaces/anycoder" target="_blank">AnyCoder</a> | <a href="https://huggingface.co/spaces" target="_blank">Hugging Face Spaces</a></p> </div> </div></body></html>""" # Upload the HTML file api.upload_file( repo_id=repo_id, repo_type="space", path_in_repo="index.html", path_or_fileobj=html_content.encode('utf-8') ) # Create a README for the space readme_content = f"""---title: {title}emoji: πcolorFrom: bluecolorTo: purplesdk: staticsdk_version: 1.0.0app_file: index.htmlpinned: false---
# {title}
This application was generated using AnyCoder, an AI-powered code generator.
## About
This space contains a web application created by describing requirements in natural language and having AI generate the corresponding HTML/CSS/JavaScript code.
## Features
- Responsive design- Modern UI/UX- Cross-browser compatibility- Mobile-friendly layout
## Generated Code
The application code was automatically generated and includes:- HTML structure- CSS styling- JavaScript functionality (if applicable)
## Created With
- [AnyCoder](https://huggingface.co/spaces/anycoder) - AI-Powered Code Generator- [Hugging Face Spaces](https://huggingface.co/spaces) - Deployment Platform
---*Generated on {time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime())}*""" api.upload_file( repo_id=repo_id, repo_type="space", path_in_repo="README.md", path_or_fileobj=readme_content.encode('utf-8') ) space_url = f"https://huggingface.co/spaces/{repo_id}" return f"β
**Success!** Your space has been created and deployed.\n\n**Space URL:** {space_url}\n\n**Repository:** {repo_id}\n\nYour application is now live and accessible to anyone with the link!" except Exception as e: return f"β **Error creating space:** {str(e)}\n\nPlease make sure you have the necessary permissions and try again."
def extract_text_from_image(image_path): """Extract text from image using OCR""" try:490 unmodified lines gr.Markdown("# AnyCoder") gr.Markdown("*AI-Powered Code Generator*") # OAuth Login Button login_btn = gr.LoginButton() # User profile display user_info = gr.Markdown("π€ **Guest User**\n*Sign in to personalize your experience*") gr.Markdown("---") # Separator # Load user info on app load demo.load(get_user_info, inputs=None, outputs=user_info) # Main input section input = gr.Textbox( label="What would you like to build?",60 unmodified lines else: gr.Markdown("β
Web search available") # Space deployment section gr.Markdown("---") gr.Markdown("**π Deploy to Space**") space_title = gr.Textbox( label="Space title", placeholder="My Awesome App", lines=1 ) deploy_btn = gr.Button("Create Space", variant="primary", size="sm") deploy_status = gr.Markdown("", visible=False) # Hidden elements for functionality model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[0]['name']}", visible=False) 43 unmodified lines outputs=[code_output, history, sandbox, history_output] ) clear_btn.click(clear_history, outputs=[history, history_output, file_input, website_url_input]) # Deploy space event handler def deploy_space_wrapper(title, current_code, oauth_token: gr.OAuthToken | None): return create_space_from_code(current_code, title, oauth_token) deploy_btn.click( deploy_space_wrapper, inputs=[space_title, code_output], outputs=deploy_status ).then( lambda: gr.update(visible=True), outputs=deploy_status )
if __name__ == "__main__": demo.queue(default_concurrency_limit=20).launch(ssr_mode=True, mcp_server=True)README.md-5
app.py+1-216