Richard Guo commited on
Commit
1bacad4
·
1 Parent(s): 6f51234
Files changed (4) hide show
  1. Dockerfile +14 -0
  2. app.py +34 -0
  3. form.html +11 -0
  4. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ WORKDIR /code
7
+
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ COPY . .
13
+
14
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import HTMLResponse
3
+ from fastapi.templating import Jinja2Templates
4
+ from typing import Optional
5
+
6
+
7
+
8
+ from pydantic import BaseModel
9
+
10
+
11
+ app = FastAPI()
12
+ templates = Jinja2Templates(directory="templates")
13
+
14
+
15
+ # Create a Pydantic model for the form data
16
+ class DatasetForm(BaseModel):
17
+ dataset_name: str
18
+
19
+
20
+
21
+ @app.get("/", response_class=HTMLResponse)
22
+ async def read_form(request: Request):
23
+ # Render the form.html template
24
+ return templates.TemplateResponse("form.html", {"request": request})
25
+
26
+
27
+ @app.post("/submit_form")
28
+ async def form_post(form_data: DatasetForm):
29
+ # Do something with form_data
30
+ print(form_data.dict())
31
+ return {"message": "Form data received!", "received_data": form_data.dict()}
32
+
33
+
34
+
form.html ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <body>
4
+ <h2>HTML Form</h2>
5
+ <form action="/submit_form" method="post">
6
+ <label for="name">Name:</label><br>
7
+ <input type="text" id="dataset_name" name="dataset_name" value=""><br>
8
+ <input type="submit" value="Submit">
9
+ </form>
10
+ </body>
11
+ </html>
requirements.txt ADDED
File without changes