Spaces:
Runtime error
Runtime error
Download app.py from sdlf/gradioapp1: direct link, hf CLI and curl.
- Browser
- Download file 3.07 kB
-
https://huggingface.co/spaces/sdlf/gradioapp1/resolve/main/app.py
- Command line
-
hf download hf://spaces/sdlf/gradioapp1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sdlf/gradioapp1/resolve/main/app.py
3.07 kB
| import requests | |
| import gradio as gr | |
| import boto3 | |
| import os | |
| import pyperclip | |
| S3_BUCKET_NAME = 'isq-filter-api-data' | |
| s3 = boto3.client('s3',region_name = 'ap-south-1', aws_access_key_id='sdfljds', aws_secret_access_key='dsf') | |
| def upload_to_s3(file_path): | |
| file_name = os.path.basename(file_path) | |
| s3.upload_file(file_path, S3_BUCKET_NAME, 'video-to-transcript/' + file_name) | |
| return file_name | |
| def call_url_api(video_url): | |
| global text | |
| api_url = 'http://35.154.235.6/whisper?type_upload=no' | |
| encoded_video_url = requests.utils.quote(video_url, safe='') | |
| full_api_url = f"{api_url}&url={encoded_video_url}" | |
| response = requests.get(full_api_url) | |
| if response.status_code == 200: | |
| data = response.json() | |
| output_video_url = data.get('url', '') | |
| language = data.get('language', '') | |
| text_extracted = data.get('transcript', '') | |
| text=text_extracted | |
| return output_video_url, language, text_extracted | |
| else: | |
| print(f"Error: {response.status_code}") | |
| return "", "", "" | |
| def call_upload_api(video_file): | |
| global text | |
| video_filename = upload_to_s3(video_file) | |
| upload_api_url = f'http://35.154.235.6/whisper?type_upload=yes&path={video_filename}' | |
| response = requests.get(upload_api_url) | |
| if response.status_code == 200: | |
| data = response.json() | |
| output_video_url = data.get('s3_file_path', '') | |
| language = data.get('language', '') | |
| text_extracted = data.get('transcript', '') | |
| text=text_extracted | |
| return output_video_url, language, text_extracted, "Copy" | |
| else: | |
| print(f"Error: {response.status_code}") | |
| return "", "", "", "copy" | |
| demo = gr.Blocks() | |
| with demo: | |
| # Define the input components and buttons | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| url_inputs = gr.components.Textbox(label="Input Video URL") | |
| b1 = gr.Button("Call with URL") | |
| file_inputs = gr.components.File(label="Upload Video") | |
| b2 = gr.Button("Call with File") | |
| # Define the output components | |
| with gr.Column(scale=4): | |
| url_outputs = [ | |
| gr.components.Textbox(label="Output Video URL"), | |
| gr.components.Textbox(label="Language"), | |
| gr.components.Textbox(label="Transcript Extracted"), | |
| gr.Button("Copy Transcript") | |
| ] | |
| b1.click(call_url_api, inputs=url_inputs, outputs=url_outputs) | |
| b2.click(call_upload_api, inputs=file_inputs, outputs=url_outputs) | |
| # Define callback function for copying transcript | |
| def copy_transcript(): | |
| print("hi") | |
| # pyperclip.copy("transcript") | |
| print("text", text) | |
| pyperclip.copy(text) | |
| # Assign callback function to copy button | |
| url_outputs[3].click(copy_transcript) | |
| # Define the layout | |
| layout = gr.Row( | |
| gr.Column([url_inputs, b1, file_inputs, b2]), | |
| gr.Column(url_outputs) | |
| ) | |
| demo.launch(share=True, auth=("user", "password"), auth_message="hey enter credentials") | |