Commit c590379a authored by Tao Jiang's avatar Tao Jiang

init

parents
Pipeline #1349 failed with stages
in 0 seconds
# Python virtual environment
venv/
env/
.env/
.venv/
ENV/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*.so
# Distribution / packaging
dist/
build/
*.egg-info/
*.egg
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Jupyter Notebook
.ipynb_checkpoints
# IDEs and editors
.idea/
.vscode/
*.swp
*.swo
*~
# Environments and Configuration
.env
.env.local
.env.development
.env.production
*.env
# Logs
*.log
logs/
log/
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Project specific
*.sqlite3
*.db
# Secret Files (explicitly declare)
*secret*
*key*
*.pem
*.key
# Machine Learning / Data Science
*.pkl
*.model
*.h5
*.hdf5
# Dependency directories
node_modules/
jspm_packages/
# Temporary files
*.bak
*.gho
*.ori
*.orig
*.tmp
# Specific to Python web frameworks
*.pot
*.pyc
local_settings.py
db.sqlite3
db.sqlite3-journal
# Celery
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Translations
*.mo
*.pot
\ No newline at end of file
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 3000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]
\ No newline at end of file
from fastapi import FastAPI
from pydantic import BaseModel
import os
# GCP vertexai
import vertexai
from vertexai.preview.generative_models import GenerativeModel, Image
import re
import base64
PROJECT_ID = os.getenv('PROJECT_ID')
REGION = os.getenv('REGION')
app = FastAPI(
title="Image Detection Service",
description="Image Detection Service",
version="0.1.0"
)
def process_base64_image(base64_string):
if ',' in base64_string:
base64_string = base64_string.split(',')[1]
try:
image_bytes = base64.b64decode(base64_string)
return Image.from_bytes(image_bytes)
except Exception as e:
print(f"图片解码错误: {e}")
return None
def clean_string(text):
return re.sub(r'[^0-9\-]', '', text)
@app.get("/", summary="default")
async def root():
return {"message": "Hello, World!"}
@app.post("/detect", summary="识别图片")
async def detect_image(request_data: dict):
base64image = request_data.get('base64image')
if base64image == "":
return {"code": 400, "data":[]}
vertexai.init(project=PROJECT_ID, location=REGION)
image = process_base64_image(base64image)
generative_multimodal_model = GenerativeModel("gemini-1.5-pro-002")
response = generative_multimodal_model.generate_content(['''Based on the text prompt at the top and the sample image above, which of the following 9 images should be selected? Multiple selections are allowed. Please number the positions starting from 1. The format should be as follows:
###
1-3-4''', image])
detect_position = ""
if response.text != "":
detect_position = clean_string(response.text)
return {"code": 200, "data":detect_position.split("-")}
\ No newline at end of file
annotated-types==0.7.0
anthropic==0.39.0
anyio==4.5.2
attrs==19.3.0
Automat==0.8.0
blinker==1.4
cachetools==5.5.0
certifi==2019.11.28
chardet==3.0.4
Click==7.0
cloud-init==23.1.2
colorama==0.4.3
command-not-found==0.3
configobj==5.0.6
constantly==15.1.0
cryptography==2.8
dbus-python==1.2.16
distro==1.9.0
distro-info===0.23ubuntu1
docstring-parser==0.16
entrypoints==0.3
exceptiongroup==1.2.2
fastapi==0.109.0
google-api-core==2.23.0
google-auth==2.36.0
google-cloud-aiplatform==1.73.0
google-cloud-bigquery==3.27.0
google-cloud-core==2.4.1
google-cloud-resource-manager==1.13.1
google-cloud-storage==2.18.2
google-crc32c==1.5.0
google-resumable-media==2.7.2
googleapis-common-protos==1.66.0
grpc-google-iam-v1==0.13.1
grpcio==1.68.0
grpcio-status==1.68.0
h11==0.14.0
httpcore==1.0.7
httplib2==0.14.0
httpx==0.27.2
hyperlink==19.0.0
idna==2.8
importlib-metadata==1.5.0
incremental==16.10.1
Jinja2==2.10.1
jiter==0.7.1
jsonpatch==1.22
jsonpointer==2.0
jsonschema==3.2.0
keyring==18.0.1
language-selector==0.1
launchpadlib==1.10.13
lazr.restfulclient==0.14.2
lazr.uri==1.0.3
MarkupSafe==1.1.0
more-itertools==4.2.0
netifaces==0.10.4
numpy==1.24.4
oauthlib==3.1.0
packaging==24.2
pexpect==4.6.0
proto-plus==1.25.0
protobuf==5.28.3
pyasn1==0.4.2
pyasn1-modules==0.2.1
pydantic==2.9.2
pydantic-core==2.23.4
PyGObject==3.36.0
PyHamcrest==1.9.0
PyJWT==1.7.1
pymacaroons==0.13.0
PyNaCl==1.3.0
pyOpenSSL==19.0.0
pyrsistent==0.15.5
pyserial==3.4
python-apt==2.0.1+ubuntu0.20.4.1
python-dateutil==2.9.0.post0
python-debian===0.1.36ubuntu1
python-dotenv==1.0.1
PyYAML==5.3.1
requests==2.22.0
requests-unixsocket==0.2.0
rsa==4.9
SecretStorage==2.3.1
service-identity==18.1.0
shapely==2.0.6
simplejson==3.16.0
six==1.14.0
sniffio==1.3.1
sos==4.4
ssh-import-id==5.10
starlette==0.35.1
systemd-python==234
Twisted==18.9.0
typing-extensions==4.12.2
ubuntu-advantage-tools==8001
ufw==0.36
unattended-upgrades==0.1
urllib3==1.25.8
uvicorn==0.24.0
wadllib==1.3.3
zipp==1.0.0
zope.interface==4.7.1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment