Spaces:
Running
Running
update
Browse files
README.md
CHANGED
|
@@ -8,11 +8,6 @@ sdk_version: 5.35.0
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
disable_embedding: true
|
| 11 |
-
hf_oauth: true
|
| 12 |
-
hf_oauth_scopes:
|
| 13 |
-
- read-repos
|
| 14 |
-
- write-repos
|
| 15 |
-
- manage-repos
|
| 16 |
---
|
| 17 |
|
| 18 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
disable_embedding: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -18,7 +18,7 @@ import json
|
|
| 18 |
import time
|
| 19 |
|
| 20 |
import gradio as gr
|
| 21 |
-
from huggingface_hub import InferenceClient
|
| 22 |
from tavily import TavilyClient
|
| 23 |
|
| 24 |
# Configuration
|
|
@@ -414,188 +414,6 @@ def demo_card_click(e: gr.EventData):
|
|
| 414 |
# Return the first demo description as fallback
|
| 415 |
return DEMO_LIST[0]['description']
|
| 416 |
|
| 417 |
-
def get_user_info(profile: gr.OAuthProfile | None) -> str:
|
| 418 |
-
"""Get user information from OAuth profile"""
|
| 419 |
-
if profile is None:
|
| 420 |
-
return "👤 **Guest User**\n*Sign in to personalize your experience*"
|
| 421 |
-
return f"👤 **{profile.name}**\n*Welcome back!*"
|
| 422 |
-
|
| 423 |
-
def create_space_from_code(html_code: str, title: str, oauth_token: gr.OAuthToken | None) -> str:
|
| 424 |
-
"""Create a new Hugging Face Space with the generated HTML code"""
|
| 425 |
-
if not oauth_token:
|
| 426 |
-
return "❌ **Error:** Please sign in with your Hugging Face account to deploy spaces."
|
| 427 |
-
|
| 428 |
-
if not html_code or not html_code.strip():
|
| 429 |
-
return "❌ **Error:** No code to deploy. Please generate some code first."
|
| 430 |
-
|
| 431 |
-
if not title or not title.strip():
|
| 432 |
-
return "❌ **Error:** Please provide a title for your space."
|
| 433 |
-
|
| 434 |
-
try:
|
| 435 |
-
# Clean up the title for use as repo name
|
| 436 |
-
import re
|
| 437 |
-
clean_title = re.sub(r'[^a-zA-Z0-9\s-]', '', title)
|
| 438 |
-
clean_title = re.sub(r'\s+', '-', clean_title).lower()
|
| 439 |
-
clean_title = clean_title[:50] # Limit length
|
| 440 |
-
|
| 441 |
-
# Get user info to create repo under their account
|
| 442 |
-
user_info = whoami(oauth_token.token)
|
| 443 |
-
username = user_info.get('name', 'unknown')
|
| 444 |
-
|
| 445 |
-
# Create unique repo ID
|
| 446 |
-
import time
|
| 447 |
-
timestamp = int(time.time())
|
| 448 |
-
repo_id = f"{username}/{clean_title}-{timestamp}"
|
| 449 |
-
|
| 450 |
-
# Create the space
|
| 451 |
-
api = HfApi(token=oauth_token.token)
|
| 452 |
-
api.create_repo(
|
| 453 |
-
repo_id=repo_id,
|
| 454 |
-
repo_type="space",
|
| 455 |
-
space_sdk="static",
|
| 456 |
-
space_hardware="cpu-basic"
|
| 457 |
-
)
|
| 458 |
-
|
| 459 |
-
# Create the HTML file content
|
| 460 |
-
html_content = f"""<!DOCTYPE html>
|
| 461 |
-
<html lang="en">
|
| 462 |
-
<head>
|
| 463 |
-
<meta charset="UTF-8">
|
| 464 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 465 |
-
<title>{title}</title>
|
| 466 |
-
<style>
|
| 467 |
-
body {{
|
| 468 |
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 469 |
-
margin: 0;
|
| 470 |
-
padding: 20px;
|
| 471 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 472 |
-
min-height: 100vh;
|
| 473 |
-
}}
|
| 474 |
-
.container {{
|
| 475 |
-
max-width: 1200px;
|
| 476 |
-
margin: 0 auto;
|
| 477 |
-
background: white;
|
| 478 |
-
border-radius: 12px;
|
| 479 |
-
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
| 480 |
-
overflow: hidden;
|
| 481 |
-
}}
|
| 482 |
-
.header {{
|
| 483 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 484 |
-
color: white;
|
| 485 |
-
padding: 30px;
|
| 486 |
-
text-align: center;
|
| 487 |
-
}}
|
| 488 |
-
.header h1 {{
|
| 489 |
-
margin: 0;
|
| 490 |
-
font-size: 2.5em;
|
| 491 |
-
font-weight: 300;
|
| 492 |
-
}}
|
| 493 |
-
.header p {{
|
| 494 |
-
margin: 10px 0 0 0;
|
| 495 |
-
opacity: 0.9;
|
| 496 |
-
font-size: 1.1em;
|
| 497 |
-
}}
|
| 498 |
-
.content {{
|
| 499 |
-
padding: 40px;
|
| 500 |
-
}}
|
| 501 |
-
.footer {{
|
| 502 |
-
background: #f8f9fa;
|
| 503 |
-
padding: 20px;
|
| 504 |
-
text-align: center;
|
| 505 |
-
color: #666;
|
| 506 |
-
border-top: 1px solid #eee;
|
| 507 |
-
}}
|
| 508 |
-
.footer a {{
|
| 509 |
-
color: #667eea;
|
| 510 |
-
text-decoration: none;
|
| 511 |
-
}}
|
| 512 |
-
.footer a:hover {{
|
| 513 |
-
text-decoration: underline;
|
| 514 |
-
}}
|
| 515 |
-
</style>
|
| 516 |
-
</head>
|
| 517 |
-
<body>
|
| 518 |
-
<div class="container">
|
| 519 |
-
<div class="header">
|
| 520 |
-
<h1>{title}</h1>
|
| 521 |
-
<p>Generated with AnyCoder - AI-Powered Code Generator</p>
|
| 522 |
-
</div>
|
| 523 |
-
<div class="content">
|
| 524 |
-
{html_code}
|
| 525 |
-
</div>
|
| 526 |
-
<div class="footer">
|
| 527 |
-
<p>🚀 Created with <a href="https://huggingface.co/spaces/anycoder" target="_blank">AnyCoder</a> |
|
| 528 |
-
<a href="https://huggingface.co/spaces" target="_blank">Hugging Face Spaces</a></p>
|
| 529 |
-
</div>
|
| 530 |
-
</div>
|
| 531 |
-
</body>
|
| 532 |
-
</html>"""
|
| 533 |
-
|
| 534 |
-
# Upload the HTML file
|
| 535 |
-
api.upload_file(
|
| 536 |
-
repo_id=repo_id,
|
| 537 |
-
repo_type="space",
|
| 538 |
-
path_in_repo="index.html",
|
| 539 |
-
path_or_fileobj=html_content.encode('utf-8')
|
| 540 |
-
)
|
| 541 |
-
|
| 542 |
-
# Create a README for the space
|
| 543 |
-
readme_content = f"""---
|
| 544 |
-
title: {title}
|
| 545 |
-
emoji: 🚀
|
| 546 |
-
colorFrom: blue
|
| 547 |
-
colorTo: purple
|
| 548 |
-
sdk: static
|
| 549 |
-
sdk_version: 1.0.0
|
| 550 |
-
app_file: index.html
|
| 551 |
-
pinned: false
|
| 552 |
-
---
|
| 553 |
-
|
| 554 |
-
# {title}
|
| 555 |
-
|
| 556 |
-
This application was generated using AnyCoder, an AI-powered code generator.
|
| 557 |
-
|
| 558 |
-
## About
|
| 559 |
-
|
| 560 |
-
This space contains a web application created by describing requirements in natural language and having AI generate the corresponding HTML/CSS/JavaScript code.
|
| 561 |
-
|
| 562 |
-
## Features
|
| 563 |
-
|
| 564 |
-
- Responsive design
|
| 565 |
-
- Modern UI/UX
|
| 566 |
-
- Cross-browser compatibility
|
| 567 |
-
- Mobile-friendly layout
|
| 568 |
-
|
| 569 |
-
## Generated Code
|
| 570 |
-
|
| 571 |
-
The application code was automatically generated and includes:
|
| 572 |
-
- HTML structure
|
| 573 |
-
- CSS styling
|
| 574 |
-
- JavaScript functionality (if applicable)
|
| 575 |
-
|
| 576 |
-
## Created With
|
| 577 |
-
|
| 578 |
-
- [AnyCoder](https://huggingface.co/spaces/anycoder) - AI-Powered Code Generator
|
| 579 |
-
- [Hugging Face Spaces](https://huggingface.co/spaces) - Deployment Platform
|
| 580 |
-
|
| 581 |
-
---
|
| 582 |
-
*Generated on {time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime())}*
|
| 583 |
-
"""
|
| 584 |
-
|
| 585 |
-
api.upload_file(
|
| 586 |
-
repo_id=repo_id,
|
| 587 |
-
repo_type="space",
|
| 588 |
-
path_in_repo="README.md",
|
| 589 |
-
path_or_fileobj=readme_content.encode('utf-8')
|
| 590 |
-
)
|
| 591 |
-
|
| 592 |
-
space_url = f"https://huggingface.co/spaces/{repo_id}"
|
| 593 |
-
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!"
|
| 594 |
-
|
| 595 |
-
except Exception as e:
|
| 596 |
-
return f"❌ **Error creating space:** {str(e)}\n\nPlease make sure you have the necessary permissions and try again."
|
| 597 |
-
|
| 598 |
-
|
| 599 |
def extract_text_from_image(image_path):
|
| 600 |
"""Extract text from image using OCR"""
|
| 601 |
try:
|
|
@@ -1092,17 +910,8 @@ with gr.Blocks(
|
|
| 1092 |
gr.Markdown("# AnyCoder")
|
| 1093 |
gr.Markdown("*AI-Powered Code Generator*")
|
| 1094 |
|
| 1095 |
-
# OAuth Login Button
|
| 1096 |
-
login_btn = gr.LoginButton()
|
| 1097 |
-
|
| 1098 |
-
# User profile display
|
| 1099 |
-
user_info = gr.Markdown("👤 **Guest User**\n*Sign in to personalize your experience*")
|
| 1100 |
-
|
| 1101 |
gr.Markdown("---") # Separator
|
| 1102 |
|
| 1103 |
-
# Load user info on app load
|
| 1104 |
-
demo.load(get_user_info, inputs=None, outputs=user_info)
|
| 1105 |
-
|
| 1106 |
# Main input section
|
| 1107 |
input = gr.Textbox(
|
| 1108 |
label="What would you like to build?",
|
|
@@ -1169,17 +978,6 @@ with gr.Blocks(
|
|
| 1169 |
else:
|
| 1170 |
gr.Markdown("✅ Web search available")
|
| 1171 |
|
| 1172 |
-
# Space deployment section
|
| 1173 |
-
gr.Markdown("---")
|
| 1174 |
-
gr.Markdown("**🚀 Deploy to Space**")
|
| 1175 |
-
space_title = gr.Textbox(
|
| 1176 |
-
label="Space title",
|
| 1177 |
-
placeholder="My Awesome App",
|
| 1178 |
-
lines=1
|
| 1179 |
-
)
|
| 1180 |
-
deploy_btn = gr.Button("Create Space", variant="primary", size="sm")
|
| 1181 |
-
deploy_status = gr.Markdown("", visible=False)
|
| 1182 |
-
|
| 1183 |
# Hidden elements for functionality
|
| 1184 |
model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[0]['name']}", visible=False)
|
| 1185 |
|
|
@@ -1229,19 +1027,6 @@ with gr.Blocks(
|
|
| 1229 |
outputs=[code_output, history, sandbox, history_output]
|
| 1230 |
)
|
| 1231 |
clear_btn.click(clear_history, outputs=[history, history_output, file_input, website_url_input])
|
| 1232 |
-
|
| 1233 |
-
# Deploy space event handler
|
| 1234 |
-
def deploy_space_wrapper(title, current_code, oauth_token: gr.OAuthToken | None):
|
| 1235 |
-
return create_space_from_code(current_code, title, oauth_token)
|
| 1236 |
-
|
| 1237 |
-
deploy_btn.click(
|
| 1238 |
-
deploy_space_wrapper,
|
| 1239 |
-
inputs=[space_title, code_output],
|
| 1240 |
-
outputs=deploy_status
|
| 1241 |
-
).then(
|
| 1242 |
-
lambda: gr.update(visible=True),
|
| 1243 |
-
outputs=deploy_status
|
| 1244 |
-
)
|
| 1245 |
|
| 1246 |
if __name__ == "__main__":
|
| 1247 |
demo.queue(default_concurrency_limit=20).launch(ssr_mode=True, mcp_server=True)
|
|
|
|
| 18 |
import time
|
| 19 |
|
| 20 |
import gradio as gr
|
| 21 |
+
from huggingface_hub import InferenceClient
|
| 22 |
from tavily import TavilyClient
|
| 23 |
|
| 24 |
# Configuration
|
|
|
|
| 414 |
# Return the first demo description as fallback
|
| 415 |
return DEMO_LIST[0]['description']
|
| 416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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code Generator*")
|
| 912 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 913 |
gr.Markdown("---") # Separator
|
| 914 |
|
|
|
|
|
|
|
|
|
|
| 915 |
# Main input section
|
| 916 |
input = gr.Textbox(
|
| 917 |
label="What would you like to build?",
|
|
|
|
| 978 |
else:
|
| 979 |
gr.Markdown("✅ Web search available")
|
| 980 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 981 |
# Hidden elements for functionality
|
| 982 |
model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[0]['name']}", visible=False)
|
| 983 |
|
|
|
|
| 1027 |
outputs=[code_output, history, sandbox, history_output]
|
| 1028 |
)
|
| 1029 |
clear_btn.click(clear_history, outputs=[history, history_output, file_input, website_url_input])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1030 |
|
| 1031 |
if __name__ == "__main__":
|
| 1032 |
demo.queue(default_concurrency_limit=20).launch(ssr_mode=True, mcp_server=True)
|