tangminhanh commited on
Commit
56263f8
1 Parent(s): 6521b5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -47
app.py CHANGED
@@ -1,50 +1,9 @@
1
- from fastapi import FastAPI, Request
2
- from fastapi.responses import HTMLResponse
3
- from pydantic import BaseModel
4
- from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
5
- import os
6
 
 
7
  app = FastAPI()
8
- token = os.getenv("token")
9
 
10
- # Load the model and tokenizer
11
- model = AutoModelForSequenceClassification.from_pretrained(
12
- "kmcs-casulit/hr_cate", token=token)
13
- tokenizer = AutoTokenizer.from_pretrained("kmcs-casulit/department-classification", token=token)
14
- pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
15
-
16
-
17
- @app.get("/", response_class=HTMLResponse)
18
- def read_root():
19
- return """
20
- <html>
21
- <body>
22
- <h1>Welcome to the Text Classification App</h1>
23
- <form action="/classify" method="post">
24
- <label for="text">Enter text:</label>
25
- <input type="text" id="text" name="text">
26
- <button type="submit">Classify</button>
27
- </form>
28
- </body>
29
- </html>
30
- """
31
-
32
- @app.post("/classify", response_class=HTMLResponse)
33
- async def classify(request: Request):
34
- form_data = await request.form()
35
- text = form_data.get('text')
36
- if not text:
37
- return HTMLResponse(content="<html><body><p>No text provided.</p></body></html>", status_code=400)
38
-
39
- output = pipe(text)
40
- classification = output[0]['label']
41
- return HTMLResponse(content=f"""
42
- <html>
43
- <body>
44
- <h1>Classification Result</h1>
45
- <p>Text: {text}</p>
46
- <p>Classification: {classification}</p>
47
- <a href="/">Back</a>
48
- </body>
49
- </html>
50
- """)
 
1
+ from fastapi import FastAPI
 
 
 
 
2
 
3
+ # Initialize the FastAPI app
4
  app = FastAPI()
 
5
 
6
+ # Define the welcome endpoint
7
+ @app.get('/')
8
+ async def welcome():
9
+ return "Welcome to our Text Classification API"