evzvereva commited on
Commit
1baa767
·
unverified ·
2 Parent(s): 980b040 18a7aca

Merge pull request #4 from kavlab/zvereva_ev

Browse files
Files changed (2) hide show
  1. requirements.txt +2 -0
  2. zvereva_ev/develop_api_app.py +23 -0
requirements.txt CHANGED
@@ -6,3 +6,5 @@ transformers==4.35.0
6
  sentencepiece==0.1.99
7
  sacremoses==0.1.1
8
  translate==3.6.1
 
 
 
6
  sentencepiece==0.1.99
7
  sacremoses==0.1.1
8
  translate==3.6.1
9
+ fastapi==0.104.1
10
+ uvicorn=0.24.0.
zvereva_ev/develop_api_app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ # Создание объекта FastAPI
5
+ app = FastAPI()
6
+ # Создание классификатора из библиотеки Hugging Face на основе пайплайна с типом "image-to-text"
7
+ classifier = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
8
+
9
+
10
+ @app.get("/")
11
+ def root():
12
+ """
13
+ Приветственное сообщение
14
+ """
15
+ return {"message": "Follow the link http://127.0.0.1:8000/predict/ and get a description of the image"}
16
+
17
+
18
+ @app.get("/predict/")
19
+ async def predict():
20
+ """
21
+ Позволяет передать изображение 'image_result.jpg' для получения его описания
22
+ """
23
+ return classifier("image_result.jpg")[0]