Spaces:
Running
Running
Download app.py from RISEFinalYear/RISE: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/spaces/RISEFinalYear/RISE/resolve/main/app.py
- Command line
-
hf download hf://spaces/RISEFinalYear/RISE/app.py
-
curl -L -o app.py https://huggingface.co/spaces/RISEFinalYear/RISE/resolve/main/app.py
2.73 kB
| from pathlib import Path | |
| import gradio as gr | |
| from fastapi import FastAPI | |
| from fastapi.responses import FileResponse | |
| from fastapi.staticfiles import StaticFiles | |
| # All website files should be in the same directory as app.py. | |
| BASE_DIR = Path(__file__).resolve().parent | |
| REQUIRED_FILES = [ | |
| "signin.html", | |
| "signup.html", | |
| "index.html", | |
| "dashboard.html", | |
| "assessment.html", | |
| "practice.html", | |
| "speaking.html", | |
| "style.css", | |
| ] | |
| # Check the files before starting the website. | |
| missing_files = [ | |
| filename | |
| for filename in REQUIRED_FILES | |
| if not (BASE_DIR / filename).is_file() | |
| ] | |
| if missing_files: | |
| raise FileNotFoundError( | |
| "The following RISE website files are missing: " | |
| + ", ".join(missing_files) | |
| ) | |
| # Gradio remains the main application used by Hugging Face Spaces. | |
| with gr.Blocks(title="RISE") as demo: | |
| gr.HTML( | |
| """ | |
| <div style="font-family:Arial,sans-serif;padding:24px"> | |
| <h2>RISE</h2> | |
| <p>AI-powered social communication coaching</p> | |
| <p> | |
| <a href="/signin.html">Sign In</a> | |
| | | |
| <a href="/signup.html">Create Account</a> | |
| </p> | |
| </div> | |
| """ | |
| ) | |
| # Add website routes to the FastAPI app used by Gradio. | |
| app = demo.app | |
| # Serve CSS, JavaScript, and other static assets from the project folder. | |
| # This mounts files at /assets/filename. | |
| app.mount( | |
| "/assets", | |
| StaticFiles(directory=str(BASE_DIR)), | |
| name="rise-assets", | |
| ) | |
| # Serve individual HTML pages. | |
| async def signin_page(): | |
| return FileResponse(BASE_DIR / "signin.html") | |
| async def signup_page(): | |
| return FileResponse(BASE_DIR / "signup.html") | |
| async def home_page(): | |
| return FileResponse(BASE_DIR / "index.html") | |
| async def dashboard_page(): | |
| return FileResponse(BASE_DIR / "dashboard.html") | |
| async def assessment_page(): | |
| return FileResponse(BASE_DIR / "assessment.html") | |
| async def practice_page(): | |
| return FileResponse(BASE_DIR / "practice.html") | |
| async def speaking_page(): | |
| return FileResponse(BASE_DIR / "speaking.html") | |
| # Serve the stylesheet at a predictable URL. | |
| async def stylesheet(): | |
| return FileResponse( | |
| BASE_DIR / "style.css", | |
| media_type="text/css", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |