File size: 2,733 Bytes
54b318d
 
 
f349438
54b318d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f349438
54b318d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f349438
54b318d
 
 
 
 
 
 
 
 
f349438
 
54b318d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

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>
                &nbsp; | &nbsp;
                <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.
@app.get("/signin.html", include_in_schema=False)
async def signin_page():
    return FileResponse(BASE_DIR / "signin.html")


@app.get("/signup.html", include_in_schema=False)
async def signup_page():
    return FileResponse(BASE_DIR / "signup.html")


@app.get("/index.html", include_in_schema=False)
async def home_page():
    return FileResponse(BASE_DIR / "index.html")


@app.get("/dashboard.html", include_in_schema=False)
async def dashboard_page():
    return FileResponse(BASE_DIR / "dashboard.html")


@app.get("/assessment.html", include_in_schema=False)
async def assessment_page():
    return FileResponse(BASE_DIR / "assessment.html")


@app.get("/practice.html", include_in_schema=False)
async def practice_page():
    return FileResponse(BASE_DIR / "practice.html")


@app.get("/speaking.html", include_in_schema=False)
async def speaking_page():
    return FileResponse(BASE_DIR / "speaking.html")


# Serve the stylesheet at a predictable URL.
@app.get("/style.css", include_in_schema=False)
async def stylesheet():
    return FileResponse(
        BASE_DIR / "style.css",
        media_type="text/css",
    )

if __name__ == "__main__":
    demo.launch()