atz21 commited on
Commit
3e76441
·
1 Parent(s): 633336b

initial app

Browse files
Files changed (6) hide show
  1. app.py +22 -0
  2. dockerfile +9 -0
  3. requirements.txt +3 -0
  4. static/scripts.js +16 -0
  5. static/style.css +12 -0
  6. templates/index.html +20 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import HTMLResponse, JSONResponse
3
+ from fastapi.staticfiles import StaticFiles
4
+ from fastapi.templating import Jinja2Templates
5
+
6
+ app = FastAPI()
7
+
8
+ app.mount("/static", StaticFiles(directory="static"), name="static")
9
+
10
+ templates = Jinja2Templates(directory="templates")
11
+
12
+
13
+ @app.get("/", response_class=HTMLResponse)
14
+ async def home(request: Request):
15
+ return templates.TemplateResponse("index.html", {"request": request})
16
+
17
+
18
+ @app.post("/api/process")
19
+ async def process_text(data: dict):
20
+ text = data.get("text", "")
21
+ result = f"Processed: {text.upper()}"
22
+ return JSONResponse({"result": result})
dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /app
4
+
5
+ COPY . /app
6
+
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ jinja2
static/scripts.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function sendText() {
2
+
3
+ const text = document.getElementById("textInput").value;
4
+
5
+ const response = await fetch("/api/process", {
6
+ method: "POST",
7
+ headers: {
8
+ "Content-Type": "application/json"
9
+ },
10
+ body: JSON.stringify({text: text})
11
+ });
12
+
13
+ const data = await response.json();
14
+
15
+ document.getElementById("result").innerText = data.result;
16
+ }
static/style.css ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: Arial;
3
+ padding: 40px;
4
+ }
5
+
6
+ input {
7
+ padding: 8px;
8
+ }
9
+
10
+ button {
11
+ padding: 8px 12px;
12
+ }
templates/index.html ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>HF Simple App</title>
5
+ <link rel="stylesheet" href="/static/style.css">
6
+ </head>
7
+
8
+ <body>
9
+
10
+ <h2>Simple HuggingFace App</h2>
11
+
12
+ <input id="textInput" placeholder="Type something">
13
+ <button onclick="sendText()">Submit</button>
14
+
15
+ <p id="result"></p>
16
+
17
+ <script src="/static/script.js"></script>
18
+
19
+ </body>
20
+ </html>