vta_routes.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Blueprint, jsonify, request
  5. from deal import RequestDeal, insert_text_mysql, get_text_by_id, PublishDeal, ArticleGeneral
  6. from applications.functions import whisper
  7. bp = Blueprint('VideosToArticle', __name__)
  8. def VTARoutes(mysql_client):
  9. """
  10. :param mysql_client:
  11. :return:
  12. """
  13. @bp.route('/videos', methods=["POST"])
  14. async def find_videos():
  15. """
  16. 更具接口获取视频信息
  17. :return:
  18. """
  19. params = await request.get_json()
  20. RD = RequestDeal(params, mysql_client)
  21. result = await RD.deal()
  22. return jsonify(result)
  23. @bp.route('/whisper', methods=["POST"])
  24. async def video_extracting():
  25. """
  26. whisper 处理文本
  27. :return:
  28. """
  29. params = await request.get_json()
  30. video_id = params['vid']
  31. video_title = params['title']
  32. try:
  33. response = whisper(video_id)
  34. await insert_text_mysql(mysql_client, video_id, response['text'], video_title)
  35. result = {"info": "success insert text into mysql", "vid": video_id}
  36. except Exception as e:
  37. result = {"error": str(e), "vid": video_id}
  38. return jsonify(result)
  39. @bp.route('/get_text', methods=["POST"])
  40. async def get_video_text():
  41. """
  42. 获取视频文本
  43. :return:
  44. """
  45. params = await request.get_json()
  46. video_id = params['vid']
  47. text = await get_text_by_id(mysql_client, video_id)
  48. if text:
  49. result = {"text": text}
  50. else:
  51. result = {"text": None}
  52. return jsonify(result)
  53. @bp.route('/publish', methods=["POST"])
  54. async def auto_publish():
  55. """
  56. auto publish article info to aigc system
  57. :return:
  58. """
  59. params = await request.get_json()
  60. P = PublishDeal(params=params)
  61. res = P.deal()
  62. return jsonify(res)
  63. @bp.route('/article', methods=["POST"])
  64. async def generate_text():
  65. """
  66. 生成文本
  67. :return:
  68. """
  69. params = await request.get_json()
  70. A = ArticleGeneral(params=params)
  71. res = A.deal()
  72. return jsonify(res)
  73. return bp