Coder Social home page Coder Social logo

tddi-model-service's People

Contributors

aerdincdal avatar seymasa avatar tarikkaankoc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tddi-model-service's Issues

๐Ÿ“Œ Bug: ImportError: cannot import name 'BERTModelMicroService' from partially initialized module 'wsgi' (most likely due to a circular import)

Error msj:


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)

Endpoint


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}

wsgi:


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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.