Team Ai
Apppublic

9farccontioshi/TranscriptApi

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
routes.cpython-310.pyc26 linesDownload Raw Back to __pycache__
1o

2y܊d��@s�ddlmZmZmZddlmZmZddlmZm	Z	m3Z4mZmZddl
mZmZddlmZddlZddlZede�Zee�ZGdd	�d	e�Ze�ed5�Gdd�de�Ze�ed
�Gdd�de�Ze�ed�Gdd�de�Ze�ed�dS)�)�	Blueprint�request�current_app)�Api�Resource)�title�summarize_youtube_video�summarize_file�summarize_string�answer)�VideoSummary�FileSummary)�dbN�	resourcesc@�eZdZdd�ZdS)�VideoTranscriptc6Cs�tt�tjj|d���}|dur||j|jd�dfSzt|�}WnddidfYSz/td|d�}t||d	|�d7|d��|dd
�}t	j8�|�t	j9��|||dd�dfWSt
yo}zWYd}~dSd}~ww)N��video_id)rr�summary���errorzVideo ID not valid�� https://www.youtube.com/watch?v=�TranscriptApi/common/audio�The title of the video is �. �10transcriptr�rrrr��)�printrr�query�	filter_by�firstrrrr�session�add�commit�	Exception)�selfrZsummaryExist�video_title�output�newVideo�e�r,�Fd:\Coding\Main_Project\TranscriptApi\TranscriptApi\resources\routes.py�gets$$11��zVideoTranscript.getN)�__name__�12__module__�__qualname__r.r,r,r,r-r
�rz/video_api/<string:video_id>c@r)�FileTranscriptcCsF|dks|dkr9ttj�tjd}tj�tj�d�|j	�}|�13tj�tj�d�|j	��t||d�\}}|j	}n|dkrHttj
d�\}}d}|d	krntj�tj�d��r_t�tj�d��t�tj�d��d14didfSt|||d
�}tj�|�tj��tj�tj�d��r�t�tj�d��t�tj�d��||d�dfS)NZpdf�txt�file�
UPLOAD_FOLDER)�
file_locationZfile_extensionZdirect_text�textzEntered Textz[ERROR]rz#We are expreriencing some issues...r)rrr)rrr)rr�files�os�path�joinr�configr.�filename�saver	r15�json�exists�shutil�rmtree�mkdirr
rr#r$r%)r'�typer5r7rr�	file_nameZ16newSummaryr,r,r-�post#s,171819zFileTranscript.postN�r/r0r1rGr,r,r,r-r3"r2r3z/file_api/<string:type>c@r)�VideoQuestionsc20Cs�ttj�tjj|d���}|dur-td|d�\}}t|�}t||d|�d|��|d�}tjj|d���}tj}zt	|d|j21d�}	|d|	d	�d22fWSddid
fYS)Nrrrrrr�question�rJ�context�rJrrrzsomething went wrongr)rrr@rr r!r"rrrr)23r'rZvideoExistsrrr(r*ZVideoExists�data�ansr,r,r-rG?s24zVideoQuestions.postNrHr,r,r,r-rI>r2rIz%/video_question_api/<string:video_id>c@r)�
FileQuestionscCsVtjj|d���}t|�|dur%ttjd|jd�}tjd|d�dfSddidfS)	N)�idrJrKrMrrzfile not foundr)	r
r r!r"rrrr@r)r'rQZtranscriptDatarOr,r,r-rGRszFileQuestions.postNrHr,r,r,r-rPQr2rPz/file_question_api/<int:id>)�flaskrrrZ
flask_restfulrrZTranscriptApi.common.utilsrrr	r25rZTranscriptApi.modelsrr
�
TranscriptApirr:rBr/r�apirZadd_resourcer3rIrPr,r,r,r-�<module>s"26