mflash123 commited on
Commit
5fb0645
·
1 Parent(s): ea05f20

Add application file

Browse files
Files changed (5) hide show
  1. Dockerfile +11 -5
  2. app.py +0 -7
  3. main.py +5 -0
  4. static/index.html +24 -0
  5. static/script.js +17 -0
Dockerfile CHANGED
@@ -1,16 +1,22 @@
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
  RUN useradd -m -u 1000 user
7
- USER user
8
- ENV PATH="/home/user/.local/bin:$PATH"
9
-
10
  WORKDIR /app
11
 
12
  COPY --chown=user ./requirements.txt requirements.txt
13
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
 
15
  COPY --chown=user . /app
16
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
1
+
2
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
3
  # you will also find guides on how best to write your Dockerfile
4
 
5
  FROM python:3.9
6
 
7
+ # The two following lines are requirements for the Dev Mode to be functional
8
+ # Learn more about the Dev Mode at https://huggingface.co/dev-mode-explorers
9
  RUN useradd -m -u 1000 user
 
 
 
10
  WORKDIR /app
11
 
12
  COPY --chown=user ./requirements.txt requirements.txt
13
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
 
15
  COPY --chown=user . /app
16
+
17
+ USER user
18
+
19
+ ENV HOME=/home/user \
20
+ PATH=/home/user/.local/bin:$PATH
21
+
22
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
app.py DELETED
@@ -1,7 +0,0 @@
1
- from fastapi import FastAPI
2
-
3
- app = FastAPI()
4
-
5
- @app.get("/")
6
- def greet_json():
7
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
main.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
2
+
3
+ @app.get("/")
4
+ def index() -> FileResponse:
5
+ return FileResponse(path="/app/static/index.html", media_type="text/html")
static/index.html ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <main>
2
+ <section id="text-gen">
3
+ <h2>Text generation using Flan T5</h2>
4
+ <p>
5
+ Model:
6
+ <a
7
+ href="https://huggingface.co/google/flan-t5-small"
8
+ rel="noreferrer"
9
+ target="_blank"
10
+ >google/flan-t5-small
11
+ </a>
12
+ </p>
13
+ <form class="text-gen-form">
14
+ <label for="text-gen-input">Text prompt</label>
15
+ <input
16
+ id="text-gen-input"
17
+ type="text"
18
+ value="German: There are many ducks"
19
+ />
20
+ <button id="text-gen-submit">Submit</button>
21
+ <p class="text-gen-output"></p>
22
+ </form>
23
+ </section>
24
+ </main>
static/script.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const textGenForm = document.querySelector(".text-gen-form");
2
+
3
+ const translateText = async (text) => {
4
+ const inferResponse = await fetch(`infer_t5?input=${text}`);
5
+ const inferJson = await inferResponse.json();
6
+
7
+ return inferJson.output;
8
+ };
9
+
10
+ textGenForm.addEventListener("submit", async (event) => {
11
+ event.preventDefault();
12
+
13
+ const textGenInput = document.getElementById("text-gen-input");
14
+ const textGenParagraph = document.querySelector(".text-gen-output");
15
+
16
+ textGenParagraph.textContent = await translateText(textGenInput.value);
17
+ });