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
79ebf1e9
Commit
79ebf1e9
authored
Apr 14, 2023
by
wangfa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
aa1dfc77
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
7 deletions
+5
-7
app.py
+1
-2
salai/common_config.py
+1
-0
salai/env.example.ini
+1
-0
salai/helper.py
+2
-5
No files found.
app.py
View file @
79ebf1e9
...
...
@@ -65,7 +65,7 @@ async def imagine(data=Body(None)):
error_message
=
""
try
:
response
=
await
mid_journey
.
imagine
(
guild_id
,
channel_id
,
prompt
)
print
(
123
)
logger
.
info
(
response
.
status
)
if
response
.
status
>=
400
:
error_message
=
"请求失败;请稍后再试"
else
:
...
...
@@ -73,7 +73,6 @@ async def imagine(data=Body(None)):
"message"
:
"您的图像正在准备中,请稍等片刻..."
}
except
Exception
as
e
:
print
(
e
)
response
=
{}
use_time
=
time
.
time
()
-
start_time
if
response
:
...
...
salai/common_config.py
View file @
79ebf1e9
...
...
@@ -7,6 +7,7 @@ config = configparser.ConfigParser()
config
.
read
(
os
.
path
.
join
(
BASE_DIR
,
'env.ini'
))
DOWNLOAD_IMAGE_PATH
=
config
.
get
(
'download'
,
'DOWNLOAD_IMAGE_PATH'
)
DOWNLOAD_URL
=
config
.
get
(
'download'
,
'DOWNLOAD_URL'
)
# oss配置
ACCESS_KEY_ID
=
config
.
get
(
'oss'
,
'ACCESS_KEY_ID'
)
...
...
salai/env.example.ini
View file @
79ebf1e9
[download]
DOWNLOAD_IMAGE_PATH
=
DOWNLOAD_URL
=
[oss]
ENDPOINT
=
...
...
salai/helper.py
View file @
79ebf1e9
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
,
BAIDU_API_SECRET_KEY
,
BAI_DU_API_KEY
,
BAI_DU_APP_ID
from
salai.common_config
import
DOWNLOAD_IMAGE_PATH
,
ACCESS_KEY_ID
,
ACCESS_KEY_SECRET
,
ENDPOINT
,
BUCKET_NAME
,
DOWNLOAD_URL
,
BAIDU_API_SECRET_KEY
,
BAI_DU_API_KEY
,
BAI_DU_APP_ID
import
hashlib
from
oss2
import
Auth
,
Bucket
from
aip
import
AipImageProcess
...
...
@@ -108,10 +108,7 @@ async def download_image(url: str, filename: str, index: int = 0):
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
)
save_name
=
f
"{DOWNLOAD_URL}/images/{file['name']}"
result
.
append
(
save_name
)
return
result
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