HTAR5 commited on
Commit
248e15e
1 Parent(s): ae3d565

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. appmod.py +30 -0
  3. requirements.txt +9 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ RUN useradd sid
10
+
11
+ USER sid
12
+
13
+ ENV HOME=/home/sid \
14
+ PATH=/home/sid/.local/bin:$PATH
15
+
16
+ WORKDIR $HOME/app
17
+
18
+ COPY --chown=sid . $HOME/app
19
+
20
+ CMD [ "uvicorn", "app:app", "--host", "0.0.0.0","--port","7860" ]
appmod.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Query
2
+ from transformers import pipeline
3
+
4
+ app = FastAPI()
5
+
6
+ def initialize_pipeline():
7
+ return pipeline("text2text-generation", model="google/flan-t5-small")
8
+
9
+ pipe = initialize_pipeline()
10
+
11
+ @app.get("/")
12
+ def home():
13
+ return {"message": "Hello Siddhant"}
14
+
15
+ @app.get("/generate")
16
+ def generate_text(
17
+ text: str = Query(None, description="Input text to generate from"),
18
+ prompt: str = Query(None, description="Optional prompt for fine-tuning the generated text"),
19
+ ):
20
+ if not text and not prompt:
21
+ return {"error": "Please provide either 'text' or 'prompt' parameter."}
22
+
23
+ if prompt:
24
+ input_text = f"{text} {prompt}" if text else prompt
25
+ else:
26
+ input_text = text
27
+
28
+ output = pipe(input_text, max_length=100, do_sample=True, top_k=50)
29
+
30
+ return {"input_text": input_text, "output": output[0]["generated_text"]}
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ uvicorn[standard]==0.17.*
4
+ sentencepiece==0.1.*
5
+ torch==1.11.*
6
+ transformers==4.*
7
+ elasticsearch
8
+ elasticsearch-dsl
9
+ PyMuPDF