nanelimon-organization / tddi-model-service Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
from wsgi import BERTModelMicroService
ImportError: cannot import name 'BERTModelMicroService' from partially initialized module 'wsgi' (most likely due to a circular import) (/Users/koc/tddi-model-service/wsgi.py)
from wsgi import BERTModelMicroService
bert_serivce = BERTModelMicroService()
@model_router.get("/example_dump_model")
async def get_label_score(texts: List[str]):
preprocess_url = "https://cryptic-oasis-68424.herokuapp.com/bulk_preprocess?turkish_char=true"
for text in texts:
preprocess_response = requests.post(
preprocess_url, json={"text": text})
processed_text = preprocess_response.json()["result"]
results = bert_serivce.predict(processed_text)
return {"success": True,
"payload": results}
from fastapi import FastAPI
from api.controllers.model_controller import model_router
from fastapi.middleware.cors import CORSMiddleware
from transformers import BertTokenizer, TFBertForSequenceClassification
from transformers import TextClassificationPipeline
BERT_MODEL_PATH = "api/static/model/bigscience_t0_model"
BERT_TOKENIZER_PATH = "api/static/model/bigscience_t0_tokenizer"
class BERTModelMicroService:
def __init__(self):
"""
Initializes a new instance of the BERTModelMicroService class.
"""
self.app = FastAPI(
title="BERT Model Micro Service",
version="0.1.0",
description="This API analyzes Turkish text using BERT, a natural language processing technology. "
"It helps Telco and OTT brands to monitor and analyze Turkish text data to identify patterns in customer feedback "
"or detect inappropriate language, and improve their customer experience and reputation management."
)
self.make_middleware()
self.bert_model = TFBertForSequenceClassification.from_pretrained(BERT_MODEL_PATH, from_pt=True)
self.bert_tokenizer = BertTokenizer.from_pretrained(BERT_TOKENIZER_PATH, do_lower_case=True)
self.pipeline = TextClassificationPipeline(model=self.bert_model, tokenizer=self.bert_tokenizer)
def predict(self, processed_text):
results = [f"{processed_text[index]} - {i['label']}" for index, i in enumerate(self.pipeline(processed_text))]
return results
def make_middleware(self):
"""
Adds middleware to the application to enable cross-origin resource sharing.
"""
self.app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
def init_routes(self):
"""
Initialize routes for the application.
Parameters
----------
app : FastAPI
The FastAPI instance to attach the routes to.
Returns
-------
None
"""
@self.app.get("/healthcheck")
async def healthcheck():
return {"success": True}
self.app.include_router(model_router, prefix="/api/v1")
BERTModelMicroService = BERTModelMicroService()
app = BERTModelMicroService.app
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.