Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python_open_ai
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haojie
python_open_ai
Commits
1c438a7a
Commit
1c438a7a
authored
Apr 14, 2023
by
wangfa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
百度图片增强
parent
ae8c6e36
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
4 deletions
+35
-4
salai/common_config.py
+4
-1
salai/env.example.ini
+6
-0
salai/helper.py
+25
-3
No files found.
salai/common_config.py
View file @
1c438a7a
...
...
@@ -18,10 +18,13 @@ SAVE_PATH = config.get('oss', 'SAVE_PATH')
# 账号配置
TOKEN
=
config
.
get
(
'user'
,
'TOKEN'
)
# redis配置
REDIS_HOST
=
config
.
get
(
'redis'
,
'HOST'
)
REDIS_PORT
=
config
.
get
(
'redis'
,
'PORT'
)
REDIS_PASSWORD
=
config
.
get
(
'redis'
,
'PASSWORD'
)
REDIS_DB
=
config
.
get
(
'redis'
,
'DB'
)
# 百度配置
BAI_DU_APP_ID
=
config
.
get
(
'baidu'
,
'APP_ID'
)
BAI_DU_API_KEY
=
config
.
get
(
'baidu'
,
'API_KEY'
)
BAIDU_API_SECRET_KEY
=
config
.
get
(
'baidu'
,
'SECRET_KEY'
)
salai/env.example.ini
View file @
1c438a7a
...
...
@@ -16,3 +16,8 @@ HOST=
PORT
=
PASSWORD
=
DB
=
[baidu]
APP_ID
=
API_KEY
=
SECRET_KEY
=
\ No newline at end of file
salai/helper.py
View file @
1c438a7a
from
PIL
import
Image
import
requests
import
os
from
salai.common_config
import
DOWNLOAD_IMAGE_PATH
,
ACCESS_KEY_ID
,
ACCESS_KEY_SECRET
,
ENDPOINT
,
BUCKET_NAME
,
SAVE_PATH
from
salai.common_config
import
DOWNLOAD_IMAGE_PATH
,
ACCESS_KEY_ID
,
ACCESS_KEY_SECRET
,
ENDPOINT
,
BUCKET_NAME
,
SAVE_PATH
,
BAIDU_API_SECRET_KEY
,
BAI_DU_API_KEY
,
BAI_DU_APP_ID
import
hashlib
from
oss2
import
Auth
,
Bucket
from
aip
import
AipImageProcess
import
base64
from
loguru
import
logger
def
split_image
(
image_file
):
"""
...
...
@@ -55,7 +57,7 @@ async def download_image(url: str, filename: str, index: int = 0):
save_image_list
=
list
()
filename
=
get_hash
(
filename
)
+
".png"
path
=
f
"{DOWNLOAD_IMAGE_PATH}{filename}"
path
=
f
"{DOWNLOAD_IMAGE_PATH}
/
{filename}"
with
open
(
path
,
'wb'
)
as
f
:
f
.
write
(
r
.
content
)
f
.
close
()
...
...
@@ -87,6 +89,26 @@ async def download_image(url: str, filename: str, index: int = 0):
result
=
list
()
if
len
(
save_image_list
)
>
0
:
for
file
in
save_image_list
:
if
index
>
0
:
client
=
AipImageProcess
(
BAI_DU_APP_ID
,
BAI_DU_API_KEY
,
BAIDU_API_SECRET_KEY
)
with
open
(
file
[
'path'
],
'rb'
)
as
fp
:
image
=
fp
.
read
()
# 图像增强
logger
.
info
(
"图像增强"
)
data
=
client
.
imageDefinitionEnhance
(
image
)
imgdata
=
base64
.
b64decode
(
data
[
"image"
])
with
open
(
file
[
'path'
],
'wb'
)
as
f
:
f
.
write
(
imgdata
)
# 无损放大
logger
.
info
(
"无损放大"
)
data
=
client
.
imageQualityEnhance
(
image
)
imgdata
=
base64
.
b64decode
(
data
[
"image"
])
with
open
(
file
[
'path'
],
'wb'
)
as
f
:
f
.
write
(
imgdata
)
save_name
=
f
"{SAVE_PATH}/{file['name']}"
await
oss_upload
(
save_name
,
file
[
'path'
])
save_name
=
"https://{}.{}/{}"
.
format
(
BUCKET_NAME
,
ENDPOINT
,
save_name
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment