Spaces:
Runtime error
Runtime error
Commit ·
f5c2623
0
Parent(s):
Add initial implementation for Media Content Localization and Dub Quality Assessment tool
Browse files- Introduced `app.py` with Gradio-based user interface
- Included `README.md` for documentation and instructions
- Added `requirements.txt` for dependency management
Files changed (3)
- README.mdAdded+49
- app.pyAdded+115
- requirements.txtAdded+4
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849---title: Localization Quality Controlemoji: 🎧colorFrom: purplecolorTo: tealsdk: gradiosdk_version: 5.34.1app_file: app.pypinned: falselicense: othershort_description: Media Content Localization and Dub Quality Assessment Space---
# Media Content Localization and Dub Quality Assessment Space
This Hugging Face Space provides a streamlined process for verifying and assessing the quality of dubbed media content. Users can upload original and dubbed audio files for validation and quality check.
## Features
- Upload original and dubbed `.wav` audio files.- Files are checked for duration constraints (maximum 30 minutes).- Automated upload to secure storage via presigned URLs.- Initiates an external processing pipeline for quality assessment.- Receive status updates on processing progress.
## Usage
1. Upload the original and dubbed `.wav` files through the interface.2. Provide your email, company name, and tolerance percentage.3. The system will validate file durations, upload files securely, and trigger processing.4. Once triggered, the system will display the response indicating processing status.
## Requirements & Setup
- Ensure your API endpoints for presigned URL retrieval and processing are correctly configured in the code.- Install necessary packages using `pip install -r requirements.txt`.- Run the app locally or deploy it as a Hugging Face Space.
## Configuration
Modify the `app.py` to update your API endpoints for:- Presigned URL generation- Triggering the media processing pipeline
For detailed configuration options, refer to the [Hugging Face Spaces documentation](https://huggingface.co/docs/hub/spaces-config-reference).
---
**Note:** This Space is designed solely for verification and quality assessment of media content. It does not handle sensitive user data beyond necessary communication.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115import gradio as grimport requestsimport waveimport contextlibimport os
def process_audio(original_audio_path, dubbed_audio_path, email, company_name, tolerance): """ This function processes the audio files, handling the logic for duration check, file upload to presigned URLs, and triggering the processing. """ # 1. Check the duration of both audio files. try: with contextlib.closing(wave.open(original_audio_path, 'r')) as f: frames = f.getnframes() rate = f.getframerate() original_duration = frames / float(rate)
with contextlib.closing(wave.open(dubbed_audio_path, 'r')) as f: frames = f.getnframes() rate = f.getframerate() dubbed_duration = frames / float(rate)
if original_duration > 1800 or dubbed_duration > 1800: return "Error: Audio duration exceeds 30 minutes."
except Exception as e: return f"Error reading audio files: {e}"
# --- ACTION REQUIRED --- # Please replace the following placeholder URLs with your actual API endpoints. presigned_url_endpoint = "https://your-api.com/get-presigned-urls" processing_endpoint = "https://your-api.com/trigger-processing" # --------------------------
# 2.1. Get presigned URLs from your endpoint. payload = { "files": [ {"name": os.path.basename(original_audio_path), "type": "audio/wav"}, {"name": os.path.basename(dubbed_audio_path), "type": "audio/wav"} ] } try: print(f"Requesting presigned URLs from: {presigned_url_endpoint}") response = requests.post(presigned_url_endpoint, json=payload) response.raise_for_status() # Raise an exception for bad status codes presigned_data = response.json()
# IMPORTANT: Adjust the following lines based on the actual JSON response # structure of your presigned URL endpoint. # This example assumes a response like: # {"original_url": "...", "dubbed_url": "..."} original_upload_url = presigned_data['original_url'] dubbed_upload_url = presigned_data['dubbed_url']
except requests.exceptions.RequestException as e: return f"Error getting presigned URLs: {e}" except KeyError: return "Error: Could not parse the presigned URL response. Please check the JSON structure."
# 2.2. Upload the audio files to the presigned URLs. try: print(f"Uploading original file to: {original_upload_url}") with open(original_audio_path, 'rb') as f: upload_response = requests.put(original_upload_url, data=f) upload_response.raise_for_status()
print(f"Uploading dubbed file to: {dubbed_upload_url}") with open(dubbed_audio_path, 'rb') as f: upload_response = requests.put(dubbed_upload_url, data=f) upload_response.raise_for_status()
except requests.exceptions.RequestException as e: return f"Error uploading files: {e}"
# 3. Call the endpoint to trigger the processing. processing_payload = { "email": email, "company_name": company_name, "tolerance": tolerance, # The keys here ('original_file', 'dubbed_file') should match what your # processing API expects. "original_file": original_upload_url, "dubbed_file": dubbed_upload_url } try: print(f"Triggering processing at: {processing_endpoint}") processing_response = requests.post(processing_endpoint, json=processing_payload) processing_response.raise_for_status() # 4. Show the response as output. return f"Processing triggered successfully. Server response: {processing_response.text}" except requests.exceptions.RequestException as e: return f"Error triggering processing: {e}"
# Create the Gradio interface for the application.demo = gr.Interface( fn=process_audio, inputs=[ gr.Audio(type="filepath", label="Original .wav file"), gr.Audio(type="filepath", label="Dubbed .wav file"), gr.Textbox(label="Email"), gr.Textbox(label="Company Name"), gr.Slider(0, 100, value=5, label="Tolerance Percentage", info="Set the tolerance for audio comparison.") ], outputs=gr.Text(label="Processing Status"), title="Audio Dubbing Verification", description="Upload original and dubbed .wav files (under 30 minutes) to start the verification process.", allow_flagging="never")
if __name__ == "__main__": # To run this file locally, you'll need to install gradio and requests: # pip install gradio requests demo.launch()1234gradiorequestswavecontextlibREADME.mdAdded+49
app.pyAdded+115
requirements.txtAdded+4