From a2c89ea04c463bac17cf7609925fae7d46109b6a Mon Sep 17 00:00:00 2001 From: jianjiang Date: Fri, 21 Apr 2023 16:45:35 +0800 Subject: [PATCH] new file: requirements.txt --- Dockerfile | 27 +++++++++++++++++++++++++++ app.py | 29 +++++++++++++++++++++++++++++ packages.txt | 2 ++ requirements.txt | 4 ++++ 4 files changed, 62 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 packages.txt create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a6c0108 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# please visit https://github.com/xfyun/aiges/releases to get stable and suitable iamges. + +FROM iflyopensource/aiges-gpu:11.2-1.17-3.9.13-ubuntu1804-v3.3.2 +RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list +RUN sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list + +RUN --mount=target=/root/packages.txt,source=packages.txt apt-get update && xargs -r -a /root/packages.txt apt-get install -y && rm -rf /var/lib/apt/lists/* + +WORKDIR /home/user/app +RUN useradd -m -u 1000 user +RUN chown -R 1000.1000 /home/user + + +RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash +RUN apt-get install git-lfs +RUN git lfs install +RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/ + + +RUN pip install --no-cache-dir pip==22.3.1 +RUN --mount=target=requirements.txt,source=requirements.txt pip install --no-cache-dir -r requirements.txt + +COPY --chown=1000 ./ /home/user/app + +RUN git clone http://172.16.59.16:3000/Seethal/sentiment_analysis_generic_dataset.git + +CMD ["python3", "app.py"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..3008e7b --- /dev/null +++ b/app.py @@ -0,0 +1,29 @@ +import gradio as gr +from transformers import pipeline, AutoTokenizer, AutoConfig, AutoModelForSequenceClassification + +modelName="sentiment_analysis_generic_dataset" + +tokenizer = AutoTokenizer.from_pretrained(modelName) +#model = AutoModelForSequenceClassification.from_pretrained(modelName) +sentimentPipeline = pipeline("sentiment-analysis", model=modelName, tokenizer=tokenizer) +Label2Des = { + "LABEL_0": "NEGATIVE", + "LABEL_1": "NEUTRAL", + "LABEL_2": "POSITIVE" +} + +def sentiment_analysis(text): + results = sentimentPipeline(text) + + return f"Sentiment: {Label2Des.get(results[0]['label'])}, Score: {results[0]['score']:.2f}" + +demo = gr.Interface(fn=sentiment_analysis, + inputs='text', + outputs='text', + title = "文本情感分析" + ) + + +if __name__ == "__main__": + demo.queue(concurrency_count=3) + demo.launch(server_name = "0.0.0.0") diff --git a/packages.txt b/packages.txt new file mode 100644 index 0000000..b399c93 --- /dev/null +++ b/packages.txt @@ -0,0 +1,2 @@ +git +curl \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..56e5592 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +gradio==3.21.0 +transformers==4.27.1 +torch==2.0.0 +timm