-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
38 lines (31 loc) · 836 Bytes
/
run.py
File metadata and controls
38 lines (31 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from fastapi import FastAPI, Request
from pydantic import BaseModel
from huggingface_hub import login
from model import MSG
import utils
import os
hf_token = os.environ.get('HUGGING_FACE_HUB_TOKEN')
if hf_token is None:
raise ValueError("Cannot find HUGGING_FACE_HUB_TOKEN")
# Hugging Face login
login(hf_token)
msg = MSG(
summarizing_model_name = "google/gemma-2-2b-it",
scoring_model_name = "gemini-1.0-pro",
device = "cpu", # depends
)
app = FastAPI()
class TextInput(BaseModel):
text: str
topics: str = ''
@app.post('/process')
async def process_text(input_data: TextInput):
text_input = input_data.text
topics = input_data.topics
msg.summarize(text_input)
msg.scoring(topics)
return {
'score': msg.score,
'reason': msg.reason,
'summary': msg.summary
}