Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TMP-23-310
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TMP-23-310
TMP-23-310
Commits
b716a0e4
Commit
b716a0e4
authored
Oct 31, 2023
by
B.A.D.A.Sathsarani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
201aec00
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
app.py
app.py
+59
-0
No files found.
app.py
0 → 100644
View file @
b716a0e4
from
flask
import
Flask
,
request
,
send_file
,
jsonify
,
make_response
,
after_this_request
import
os
from
chatbot
import
ChatBot
app
=
Flask
(
__name__
)
UPLOAD_FOLDER
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'uploads'
)
app
.
config
[
'UPLOAD_FOLDER'
]
=
UPLOAD_FOLDER
@
app
.
route
(
'/chatbot'
,
methods
=
[
'POST'
])
def
process_audio
():
try
:
script_folder
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
audio_file
=
request
.
files
[
'audio'
]
language
=
request
.
form
[
'language'
]
grade
=
int
(
request
.
form
[
'grade'
])
audio_path
=
os
.
path
.
join
(
app
.
config
[
'UPLOAD_FOLDER'
],
audio_file
.
filename
)
audio_file
.
save
(
audio_path
)
chatbot
=
ChatBot
(
audio_path
,
language
,
grade
)
response_text
=
chatbot
.
run_chatbot
()
res_path
=
os
.
path
.
join
(
script_folder
,
'response'
)
processed_audio_path
=
os
.
path
.
join
(
res_path
,
'output.mp3'
)
if
os
.
path
.
exists
(
processed_audio_path
):
# Prepare the response data
response_data
=
{
'response_text'
:
response_text
,
'audio_path'
:
processed_audio_path
# Include the audio file path
}
# Send the audio file as an attachment
@
after_this_request
def
add_file_to_response
(
response
):
with
open
(
processed_audio_path
,
'rb'
)
as
audio_file
:
response
.
data
=
audio_file
.
read
()
response
.
headers
[
'Content-Disposition'
]
=
f
'attachment; filename=output.mp3'
return
response
# Return the JSON response data
return
jsonify
(
response_data
)
else
:
# If audio file doesn't exist, return response text only
return
jsonify
({
'response_text'
:
response_text
})
except
Exception
as
e
:
return
jsonify
({
'error_message'
:
str
(
e
)})
+
#if __name__ == '__main__':
# app.run(port=5000, host='192.168.8.133', debug=True)
#
# # ##when ngrock up
if
__name__
==
'__main__'
:
app
.
run
(
port
=
5000
,
debug
=
True
)
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