Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	
		bravedims
		
	commited on
		
		
					Commit 
							
							·
						
						8be8b4b
	
1
								Parent(s):
							
							e29fad2
								
Replace ElevenLabs with HuggingFace TTS (SpeechT5)
Browse files✅ Benefits:
- No API keys required - completely free and self-contained
- Uses Microsoft SpeechT5 model for high-quality TTS
- Voice ID mapping for compatibility with existing API
- Multiple speaker embeddings for voice variety
- Runs entirely on HuggingFace infrastructure
📁 Changes:
- Add hf_tts_client.py with SpeechT5 TTS implementation
- Update app.py to use HF TTS instead of ElevenLabs
- Update requirements.txt with TTS dependencies
- Update README.md to reflect HF TTS usage
- Add test_hf_tts.py for TTS testing
- Remove dependency on external ElevenLabs API
🎯 Voice mapping:
- Same voice_id parameters work (mapped to speaker embeddings)
- 7+ different voices available
- No rate limits or quotas
- API_DOCUMENTATION.md +177 -0
- Dockerfile.backup +51 -0
- README.md +8 -7
- api_urls.txt +25 -0
- app.py +8 -5
- app.py.backup +482 -0
- get_voices.ps1 +29 -0
- hf_tts_client.py +115 -0
- requirements.txt +8 -0
- test_api.ps1 +31 -0
- test_audio_url.ps1 +24 -0
- test_elevenlabs.ps1 +50 -0
- test_fixes.ps1 +18 -0
- test_generate.ps1 +31 -0
- test_hf_tts.py +23 -0
- voice_ids_reference.txt +32 -0
    	
        API_DOCUMENTATION.md
    ADDED
    
    | @@ -0,0 +1,177 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # 🔌 OmniAvatar API Documentation
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ## POST /generate - Avatar Generation
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ### Request Format
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            **URL:** `https://huggingface.co/spaces/bravedims/AI_Avatar_Chat/api/generate`
         | 
| 8 | 
            +
            **Method:** `POST`
         | 
| 9 | 
            +
            **Content-Type:** `application/json`
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ### Request Body (JSON)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ```json
         | 
| 14 | 
            +
            {
         | 
| 15 | 
            +
              "prompt": "string",
         | 
| 16 | 
            +
              "text_to_speech": "string (optional)",
         | 
| 17 | 
            +
              "elevenlabs_audio_url": "string (optional)",
         | 
| 18 | 
            +
              "voice_id": "string (optional, default: '21m00Tcm4TlvDq8ikWAM')",
         | 
| 19 | 
            +
              "image_url": "string (optional)",
         | 
| 20 | 
            +
              "guidance_scale": "float (default: 5.0)",
         | 
| 21 | 
            +
              "audio_scale": "float (default: 3.0)",
         | 
| 22 | 
            +
              "num_steps": "int (default: 30)",
         | 
| 23 | 
            +
              "sp_size": "int (default: 1)",
         | 
| 24 | 
            +
              "tea_cache_l1_thresh": "float (optional)"
         | 
| 25 | 
            +
            }
         | 
| 26 | 
            +
            ```
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ### Request Parameters
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            | Field | Type | Required | Description |
         | 
| 31 | 
            +
            |-------|------|----------|-------------|
         | 
| 32 | 
            +
            | `prompt` | string | ✅ | Character behavior description |
         | 
| 33 | 
            +
            | `text_to_speech` | string | ❌ | Text to convert to speech via ElevenLabs |
         | 
| 34 | 
            +
            | `elevenlabs_audio_url` | string | ❌ | Direct URL to audio file |
         | 
| 35 | 
            +
            | `voice_id` | string | ❌ | ElevenLabs voice ID (default: Rachel) |
         | 
| 36 | 
            +
            | `image_url` | string | ❌ | Reference image URL |
         | 
| 37 | 
            +
            | `guidance_scale` | float | ❌ | Prompt following strength (4-6 recommended) |
         | 
| 38 | 
            +
            | `audio_scale` | float | ❌ | Lip-sync accuracy (3-5 recommended) |
         | 
| 39 | 
            +
            | `num_steps` | int | ❌ | Generation steps (20-50 recommended) |
         | 
| 40 | 
            +
            | `sp_size` | int | ❌ | Parallel processing size |
         | 
| 41 | 
            +
            | `tea_cache_l1_thresh` | float | ❌ | Cache threshold optimization |
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            **Note:** Either `text_to_speech` OR `elevenlabs_audio_url` must be provided.
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            ### Example Request
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            ```json
         | 
| 48 | 
            +
            {
         | 
| 49 | 
            +
              "prompt": "A professional teacher explaining a mathematical concept with clear gestures",
         | 
| 50 | 
            +
              "text_to_speech": "Hello students! Today we're going to learn about calculus and how derivatives work in real life.",
         | 
| 51 | 
            +
              "voice_id": "21m00Tcm4TlvDq8ikWAM",
         | 
| 52 | 
            +
              "image_url": "https://example.com/teacher.jpg",
         | 
| 53 | 
            +
              "guidance_scale": 5.0,
         | 
| 54 | 
            +
              "audio_scale": 3.5,
         | 
| 55 | 
            +
              "num_steps": 30
         | 
| 56 | 
            +
            }
         | 
| 57 | 
            +
            ```
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            ### Response Format
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            **Success Response (200 OK):**
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            ```json
         | 
| 64 | 
            +
            {
         | 
| 65 | 
            +
              "message": "string",
         | 
| 66 | 
            +
              "output_path": "string",
         | 
| 67 | 
            +
              "processing_time": "float",
         | 
| 68 | 
            +
              "audio_generated": "boolean"
         | 
| 69 | 
            +
            }
         | 
| 70 | 
            +
            ```
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            ### Response Fields
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            | Field | Type | Description |
         | 
| 75 | 
            +
            |-------|------|-------------|
         | 
| 76 | 
            +
            | `message` | string | Success/status message |
         | 
| 77 | 
            +
            | `output_path` | string | Path to generated video file |
         | 
| 78 | 
            +
            | `processing_time` | float | Processing time in seconds |
         | 
| 79 | 
            +
            | `audio_generated` | boolean | Whether audio was generated from text |
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            ### Example Response
         | 
| 82 | 
            +
             | 
| 83 | 
            +
            ```json
         | 
| 84 | 
            +
            {
         | 
| 85 | 
            +
              "message": "Avatar generation completed successfully",
         | 
| 86 | 
            +
              "output_path": "./outputs/avatar_20240807_130512.mp4",
         | 
| 87 | 
            +
              "processing_time": 45.67,
         | 
| 88 | 
            +
              "audio_generated": true
         | 
| 89 | 
            +
            }
         | 
| 90 | 
            +
            ```
         | 
| 91 | 
            +
             | 
| 92 | 
            +
            ### Error Responses
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            **400 Bad Request:**
         | 
| 95 | 
            +
            ```json
         | 
| 96 | 
            +
            {
         | 
| 97 | 
            +
              "detail": "Either text_to_speech or elevenlabs_audio_url must be provided"
         | 
| 98 | 
            +
            }
         | 
| 99 | 
            +
            ```
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            **500 Internal Server Error:**
         | 
| 102 | 
            +
            ```json
         | 
| 103 | 
            +
            {
         | 
| 104 | 
            +
              "detail": "Model not loaded"
         | 
| 105 | 
            +
            }
         | 
| 106 | 
            +
            ```
         | 
| 107 | 
            +
             | 
| 108 | 
            +
            **503 Service Unavailable:**
         | 
| 109 | 
            +
            ```json
         | 
| 110 | 
            +
            {
         | 
| 111 | 
            +
              "detail": "Model not loaded"
         | 
| 112 | 
            +
            }
         | 
| 113 | 
            +
            ```
         | 
| 114 | 
            +
             | 
| 115 | 
            +
            ### Available ElevenLabs Voices
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            | Voice ID | Name | Description |
         | 
| 118 | 
            +
            |----------|------|-------------|
         | 
| 119 | 
            +
            | `21m00Tcm4TlvDq8ikWAM` | Rachel | Default, clear female voice |
         | 
| 120 | 
            +
            | `pNInz6obpgDQGcFmaJgB` | Adam | Professional male voice |
         | 
| 121 | 
            +
            | `EXAVITQu4vr4xnSDxMaL` | Bella | Expressive female voice |
         | 
| 122 | 
            +
             | 
| 123 | 
            +
            ### Usage Examples
         | 
| 124 | 
            +
             | 
| 125 | 
            +
            #### With Text-to-Speech
         | 
| 126 | 
            +
            ```bash
         | 
| 127 | 
            +
            curl -X POST "https://huggingface.co/spaces/bravedims/AI_Avatar_Chat/api/generate" \
         | 
| 128 | 
            +
              -H "Content-Type: application/json" \
         | 
| 129 | 
            +
              -d '{
         | 
| 130 | 
            +
                "prompt": "A friendly presenter speaking confidently",
         | 
| 131 | 
            +
                "text_to_speech": "Welcome to our AI avatar demonstration!",
         | 
| 132 | 
            +
                "voice_id": "21m00Tcm4TlvDq8ikWAM",
         | 
| 133 | 
            +
                "guidance_scale": 5.5,
         | 
| 134 | 
            +
                "audio_scale": 4.0
         | 
| 135 | 
            +
              }'
         | 
| 136 | 
            +
            ```
         | 
| 137 | 
            +
             | 
| 138 | 
            +
            #### With Audio URL
         | 
| 139 | 
            +
            ```bash
         | 
| 140 | 
            +
            curl -X POST "https://huggingface.co/spaces/bravedims/AI_Avatar_Chat/api/generate" \
         | 
| 141 | 
            +
              -H "Content-Type: application/json" \
         | 
| 142 | 
            +
              -d '{
         | 
| 143 | 
            +
                "prompt": "A news anchor delivering headlines",
         | 
| 144 | 
            +
                "elevenlabs_audio_url": "https://example.com/audio.mp3",
         | 
| 145 | 
            +
                "image_url": "https://example.com/anchor.jpg",
         | 
| 146 | 
            +
                "num_steps": 40
         | 
| 147 | 
            +
              }'
         | 
| 148 | 
            +
            ```
         | 
| 149 | 
            +
             | 
| 150 | 
            +
            ### Other Endpoints
         | 
| 151 | 
            +
             | 
| 152 | 
            +
            #### GET /health - Health Check
         | 
| 153 | 
            +
            ```json
         | 
| 154 | 
            +
            {
         | 
| 155 | 
            +
              "status": "healthy",
         | 
| 156 | 
            +
              "model_loaded": true,
         | 
| 157 | 
            +
              "device": "cuda",
         | 
| 158 | 
            +
              "supports_elevenlabs": true,
         | 
| 159 | 
            +
              "supports_image_urls": true,
         | 
| 160 | 
            +
              "supports_text_to_speech": true,
         | 
| 161 | 
            +
              "elevenlabs_api_configured": true
         | 
| 162 | 
            +
            }
         | 
| 163 | 
            +
            ```
         | 
| 164 | 
            +
             | 
| 165 | 
            +
            #### GET /docs - FastAPI Documentation
         | 
| 166 | 
            +
            Interactive API documentation available at `/docs` endpoint.
         | 
| 167 | 
            +
             | 
| 168 | 
            +
            ### Rate Limits & Performance
         | 
| 169 | 
            +
             | 
| 170 | 
            +
            - **Processing Time:** 30-120 seconds depending on complexity
         | 
| 171 | 
            +
            - **Max Video Length:** Determined by audio length
         | 
| 172 | 
            +
            - **Supported Formats:** MP4 output, MP3/WAV audio input
         | 
| 173 | 
            +
            - **GPU Acceleration:** Enabled on T4+ hardware
         | 
| 174 | 
            +
             | 
| 175 | 
            +
            ---
         | 
| 176 | 
            +
             | 
| 177 | 
            +
            **Live API Base URL:** `https://huggingface.co/spaces/bravedims/AI_Avatar_Chat`
         | 
    	
        Dockerfile.backup
    ADDED
    
    | @@ -0,0 +1,51 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
         | 
| 2 | 
            +
            # Use NVIDIA PyTorch base image for GPU support
         | 
| 3 | 
            +
            FROM pytorch/pytorch:2.1.0-cuda12.1-cudnn8-devel
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            # Create user as required by HF Spaces
         | 
| 6 | 
            +
            RUN useradd -m -u 1000 user
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            # Install system dependencies
         | 
| 9 | 
            +
            RUN apt-get update && apt-get install -y \
         | 
| 10 | 
            +
                git \
         | 
| 11 | 
            +
                wget \
         | 
| 12 | 
            +
                curl \
         | 
| 13 | 
            +
                libgl1-mesa-glx \
         | 
| 14 | 
            +
                libglib2.0-0 \
         | 
| 15 | 
            +
                libsm6 \
         | 
| 16 | 
            +
                libxext6 \
         | 
| 17 | 
            +
                libxrender-dev \
         | 
| 18 | 
            +
                libgomp1 \
         | 
| 19 | 
            +
                libgoogle-perftools4 \
         | 
| 20 | 
            +
                libtcmalloc-minimal4 \
         | 
| 21 | 
            +
                ffmpeg \
         | 
| 22 | 
            +
                && apt-get clean \
         | 
| 23 | 
            +
                && rm -rf /var/lib/apt/lists/*
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            # Switch to user
         | 
| 26 | 
            +
            USER user
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            # Set environment variables for user
         | 
| 29 | 
            +
            ENV PATH="/home/user/.local/bin:$PATH"
         | 
| 30 | 
            +
            ENV PYTHONPATH=/app
         | 
| 31 | 
            +
            ENV GRADIO_SERVER_NAME=0.0.0.0
         | 
| 32 | 
            +
            ENV GRADIO_SERVER_PORT=7860
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            # Set working directory
         | 
| 35 | 
            +
            WORKDIR /app
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            # Copy requirements and install Python dependencies
         | 
| 38 | 
            +
            COPY --chown=user ./requirements.txt requirements.txt
         | 
| 39 | 
            +
            RUN pip install --no-cache-dir --upgrade -r requirements.txt
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            # Copy application code
         | 
| 42 | 
            +
            COPY --chown=user . /app
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            # Create necessary directories
         | 
| 45 | 
            +
            RUN mkdir -p pretrained_models outputs
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            # Expose port (required by HF Spaces to be 7860)
         | 
| 48 | 
            +
            EXPOSE 7860
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            # Start the application
         | 
| 51 | 
            +
            CMD ["python", "app.py"]
         | 
    	
        README.md
    CHANGED
    
    | @@ -10,14 +10,14 @@ suggested_hardware: a10g-small | |
| 10 | 
             
            suggested_storage: large
         | 
| 11 | 
             
            ---
         | 
| 12 |  | 
| 13 | 
            -
            # 🎭 OmniAvatar-14B with  | 
| 14 |  | 
| 15 | 
            -
            An advanced AI avatar generation system that creates realistic talking avatars from text prompts and speech. This space combines the power of OmniAvatar-14B with  | 
| 16 |  | 
| 17 | 
             
            ## ✨ Features
         | 
| 18 |  | 
| 19 | 
             
            - **🎯 Text-to-Avatar Generation**: Generate avatars from descriptive text prompts
         | 
| 20 | 
            -
            - **🗣️  | 
| 21 | 
             
            - **🎵 Audio URL Support**: Use pre-generated audio files
         | 
| 22 | 
             
            - **🖼️ Image Reference Support**: Guide avatar appearance with reference images
         | 
| 23 | 
             
            - **⚡ Real-time Processing**: Fast generation with GPU acceleration
         | 
| @@ -48,7 +48,7 @@ An advanced AI avatar generation system that creates realistic talking avatars f | |
| 48 | 
             
            ## 🔧 Technical Details
         | 
| 49 |  | 
| 50 | 
             
            - **Model**: OmniAvatar-14B for video generation
         | 
| 51 | 
            -
            -  | 
| 52 | 
             
            - **Framework**: FastAPI + Gradio interface
         | 
| 53 | 
             
            - **GPU**: Optimized for T4 and higher
         | 
| 54 | 
             
            - **Storage**: Requires large storage due to 14B parameter models (~70GB total)
         | 
| @@ -59,9 +59,9 @@ An advanced AI avatar generation system that creates realistic talking avatars f | |
| 59 | 
             
            - `POST /generate` - Generate avatar video
         | 
| 60 | 
             
            - `/gradio` - Interactive web interface
         | 
| 61 |  | 
| 62 | 
            -
            ## 🔐  | 
| 63 |  | 
| 64 | 
            -
             | 
| 65 |  | 
| 66 | 
             
            ## 📄 License
         | 
| 67 |  | 
| @@ -69,7 +69,8 @@ Apache 2.0 - See LICENSE file for details | |
| 69 |  | 
| 70 | 
             
            ---
         | 
| 71 |  | 
| 72 | 
            -
            *Powered by OmniAvatar-14B and  | 
| 73 |  | 
| 74 | 
             
            **Note**: This space requires large storage capacity due to the 14B parameter models. The models are downloaded on first startup and cached for subsequent uses.
         | 
| 75 |  | 
|  | 
|  | |
| 10 | 
             
            suggested_storage: large
         | 
| 11 | 
             
            ---
         | 
| 12 |  | 
| 13 | 
            +
            # 🎭 OmniAvatar-14B with HuggingFace TTS
         | 
| 14 |  | 
| 15 | 
            +
            An advanced AI avatar generation system that creates realistic talking avatars from text prompts and speech. This space combines the power of OmniAvatar-14B with HuggingFace SpeechT5 text-to-speech for seamless avatar creation.
         | 
| 16 |  | 
| 17 | 
             
            ## ✨ Features
         | 
| 18 |  | 
| 19 | 
             
            - **🎯 Text-to-Avatar Generation**: Generate avatars from descriptive text prompts
         | 
| 20 | 
            +
            - **🗣️ HuggingFace TTS Integration**: High-quality text-to-speech synthesis
         | 
| 21 | 
             
            - **🎵 Audio URL Support**: Use pre-generated audio files
         | 
| 22 | 
             
            - **🖼️ Image Reference Support**: Guide avatar appearance with reference images
         | 
| 23 | 
             
            - **⚡ Real-time Processing**: Fast generation with GPU acceleration
         | 
|  | |
| 48 | 
             
            ## 🔧 Technical Details
         | 
| 49 |  | 
| 50 | 
             
            - **Model**: OmniAvatar-14B for video generation
         | 
| 51 | 
            +
            - ****TTS**: Microsoft SpeechT5 (HuggingFace) for high-quality speech synthesis
         | 
| 52 | 
             
            - **Framework**: FastAPI + Gradio interface
         | 
| 53 | 
             
            - **GPU**: Optimized for T4 and higher
         | 
| 54 | 
             
            - **Storage**: Requires large storage due to 14B parameter models (~70GB total)
         | 
|  | |
| 59 | 
             
            - `POST /generate` - Generate avatar video
         | 
| 60 | 
             
            - `/gradio` - Interactive web interface
         | 
| 61 |  | 
| 62 | 
            +
            ## 🔐 No API Keys Required
         | 
| 63 |  | 
| 64 | 
            +
            This space uses open-source HuggingFace models for text-to-speech. No external API keys or accounts needed!
         | 
| 65 |  | 
| 66 | 
             
            ## 📄 License
         | 
| 67 |  | 
|  | |
| 69 |  | 
| 70 | 
             
            ---
         | 
| 71 |  | 
| 72 | 
            +
            *Powered by OmniAvatar-14B and HuggingFace TTS*
         | 
| 73 |  | 
| 74 | 
             
            **Note**: This space requires large storage capacity due to the 14B parameter models. The models are downloaded on first startup and cached for subsequent uses.
         | 
| 75 |  | 
| 76 | 
            +
             | 
    	
        api_urls.txt
    ADDED
    
    | @@ -0,0 +1,25 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Your HF Space API URLs:
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Base URL: https://bravedims-ai-avatar-chat.hf.space
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Health Check:
         | 
| 6 | 
            +
            GET https://bravedims-ai-avatar-chat.hf.space/health
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            Generate Avatar:
         | 
| 9 | 
            +
            POST https://bravedims-ai-avatar-chat.hf.space/generate
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Gradio Interface:
         | 
| 12 | 
            +
            https://bravedims-ai-avatar-chat.hf.space/gradio
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            # Example API call using the JSON you selected:
         | 
| 15 | 
            +
            curl -X POST "https://bravedims-ai-avatar-chat.hf.space/generate" \
         | 
| 16 | 
            +
              -H "Content-Type: application/json" \
         | 
| 17 | 
            +
              -d '{
         | 
| 18 | 
            +
                "prompt": "A professional teacher explaining a mathematical concept with clear gestures",
         | 
| 19 | 
            +
                "text_to_speech": "Hello students! Today we'\''re going to learn about calculus and how derivatives work in real life.",
         | 
| 20 | 
            +
                "voice_id": "21m00Tcm4TlvDq8ikWAM",
         | 
| 21 | 
            +
                "image_url": "https://example.com/teacher.jpg",
         | 
| 22 | 
            +
                "guidance_scale": 5.0,
         | 
| 23 | 
            +
                "audio_scale": 3.5,
         | 
| 24 | 
            +
                "num_steps": 30
         | 
| 25 | 
            +
              }'
         | 
    	
        app.py
    CHANGED
    
    | @@ -17,6 +17,7 @@ from typing import Optional | |
| 17 | 
             
            import aiohttp
         | 
| 18 | 
             
            import asyncio
         | 
| 19 | 
             
            from dotenv import load_dotenv
         | 
|  | |
| 20 |  | 
| 21 | 
             
            # Load environment variables
         | 
| 22 | 
             
            load_dotenv()
         | 
| @@ -119,9 +120,9 @@ class OmniAvatarAPI: | |
| 119 | 
             
                def __init__(self):
         | 
| 120 | 
             
                    self.model_loaded = False
         | 
| 121 | 
             
                    self.device = "cuda" if torch.cuda.is_available() else "cpu"
         | 
| 122 | 
            -
                    self. | 
| 123 | 
             
                    logger.info(f"Using device: {self.device}")
         | 
| 124 | 
            -
                    logger.info( | 
| 125 |  | 
| 126 | 
             
                def load_model(self):
         | 
| 127 | 
             
                    """Load the OmniAvatar model"""
         | 
| @@ -208,10 +209,10 @@ class OmniAvatarAPI: | |
| 208 | 
             
                            logger.info(f"Generating speech from text: {request.text_to_speech[:50]}...")
         | 
| 209 | 
             
                            logger.info(f"Using voice ID: {voice_id}")
         | 
| 210 |  | 
| 211 | 
            -
                            if not  | 
| 212 | 
             
                                raise HTTPException(status_code=503, detail="ElevenLabs API key not configured")
         | 
| 213 |  | 
| 214 | 
            -
                            audio_path = await self. | 
| 215 | 
             
                                request.text_to_speech, 
         | 
| 216 | 
             
                                voice_id
         | 
| 217 | 
             
                            )
         | 
| @@ -442,7 +443,7 @@ iface = gr.Interface( | |
| 442 | 
             
                    gr.Slider(minimum=10, maximum=100, value=30, step=1, label="Number of Steps", info="20-50 recommended")
         | 
| 443 | 
             
                ],
         | 
| 444 | 
             
                outputs=gr.Video(label="Generated Avatar Video"),
         | 
| 445 | 
            -
                title="🎭 OmniAvatar-14B with  | 
| 446 | 
             
                description="""
         | 
| 447 | 
             
                Generate avatar videos with lip-sync from text prompts and speech.
         | 
| 448 |  | 
| @@ -497,3 +498,5 @@ if __name__ == "__main__": | |
| 497 | 
             
                uvicorn.run(app, host="0.0.0.0", port=7860)
         | 
| 498 |  | 
| 499 |  | 
|  | |
|  | 
|  | |
| 17 | 
             
            import aiohttp
         | 
| 18 | 
             
            import asyncio
         | 
| 19 | 
             
            from dotenv import load_dotenv
         | 
| 20 | 
            +
            from hf_tts_client import HuggingFaceTTSClient
         | 
| 21 |  | 
| 22 | 
             
            # Load environment variables
         | 
| 23 | 
             
            load_dotenv()
         | 
|  | |
| 120 | 
             
                def __init__(self):
         | 
| 121 | 
             
                    self.model_loaded = False
         | 
| 122 | 
             
                    self.device = "cuda" if torch.cuda.is_available() else "cpu"
         | 
| 123 | 
            +
                    self.tts_client = HuggingFaceTTSClient()
         | 
| 124 | 
             
                    logger.info(f"Using device: {self.device}")
         | 
| 125 | 
            +
                    logger.info("Using HuggingFace TTS (SpeechT5) - No API key required")
         | 
| 126 |  | 
| 127 | 
             
                def load_model(self):
         | 
| 128 | 
             
                    """Load the OmniAvatar model"""
         | 
|  | |
| 209 | 
             
                            logger.info(f"Generating speech from text: {request.text_to_speech[:50]}...")
         | 
| 210 | 
             
                            logger.info(f"Using voice ID: {voice_id}")
         | 
| 211 |  | 
| 212 | 
            +
                            if not True  # HF TTS always available:
         | 
| 213 | 
             
                                raise HTTPException(status_code=503, detail="ElevenLabs API key not configured")
         | 
| 214 |  | 
| 215 | 
            +
                            audio_path = await self.tts_client.text_to_speech(
         | 
| 216 | 
             
                                request.text_to_speech, 
         | 
| 217 | 
             
                                voice_id
         | 
| 218 | 
             
                            )
         | 
|  | |
| 443 | 
             
                    gr.Slider(minimum=10, maximum=100, value=30, step=1, label="Number of Steps", info="20-50 recommended")
         | 
| 444 | 
             
                ],
         | 
| 445 | 
             
                outputs=gr.Video(label="Generated Avatar Video"),
         | 
| 446 | 
            +
                title="🎭 OmniAvatar-14B with HuggingFace TTS",
         | 
| 447 | 
             
                description="""
         | 
| 448 | 
             
                Generate avatar videos with lip-sync from text prompts and speech.
         | 
| 449 |  | 
|  | |
| 498 | 
             
                uvicorn.run(app, host="0.0.0.0", port=7860)
         | 
| 499 |  | 
| 500 |  | 
| 501 | 
            +
             | 
| 502 | 
            +
             | 
    	
        app.py.backup
    ADDED
    
    | @@ -0,0 +1,482 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            import os
         | 
| 2 | 
            +
            import torch
         | 
| 3 | 
            +
            import tempfile
         | 
| 4 | 
            +
            import gradio as gr
         | 
| 5 | 
            +
            from fastapi import FastAPI, HTTPException
         | 
| 6 | 
            +
            from fastapi.middleware.cors import CORSMiddleware
         | 
| 7 | 
            +
            from pydantic import BaseModel, HttpUrl
         | 
| 8 | 
            +
            import subprocess
         | 
| 9 | 
            +
            import json
         | 
| 10 | 
            +
            from pathlib import Path
         | 
| 11 | 
            +
            import logging
         | 
| 12 | 
            +
            import requests
         | 
| 13 | 
            +
            from urllib.parse import urlparse
         | 
| 14 | 
            +
            from PIL import Image
         | 
| 15 | 
            +
            import io
         | 
| 16 | 
            +
            from typing import Optional
         | 
| 17 | 
            +
            import aiohttp
         | 
| 18 | 
            +
            import asyncio
         | 
| 19 | 
            +
            from dotenv import load_dotenv
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            # Load environment variables
         | 
| 22 | 
            +
            load_dotenv()
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            # Set up logging
         | 
| 25 | 
            +
            logging.basicConfig(level=logging.INFO)
         | 
| 26 | 
            +
            logger = logging.getLogger(__name__)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            app = FastAPI(title="OmniAvatar-14B API with ElevenLabs", version="1.0.0")
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            # Add CORS middleware
         | 
| 31 | 
            +
            app.add_middleware(
         | 
| 32 | 
            +
                CORSMiddleware,
         | 
| 33 | 
            +
                allow_origins=["*"],
         | 
| 34 | 
            +
                allow_credentials=True,
         | 
| 35 | 
            +
                allow_methods=["*"],
         | 
| 36 | 
            +
                allow_headers=["*"],
         | 
| 37 | 
            +
            )
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            # Pydantic models for request/response
         | 
| 40 | 
            +
            class GenerateRequest(BaseModel):
         | 
| 41 | 
            +
                prompt: str
         | 
| 42 | 
            +
                text_to_speech: Optional[str] = None  # Text to convert to speech
         | 
| 43 | 
            +
                elevenlabs_audio_url: Optional[HttpUrl] = None  # Direct audio URL
         | 
| 44 | 
            +
                voice_id: Optional[str] = "21m00Tcm4TlvDq8ikWAM"  # Default ElevenLabs voice
         | 
| 45 | 
            +
                image_url: Optional[HttpUrl] = None
         | 
| 46 | 
            +
                guidance_scale: float = 5.0
         | 
| 47 | 
            +
                audio_scale: float = 3.0
         | 
| 48 | 
            +
                num_steps: int = 30
         | 
| 49 | 
            +
                sp_size: int = 1
         | 
| 50 | 
            +
                tea_cache_l1_thresh: Optional[float] = None
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            class GenerateResponse(BaseModel):
         | 
| 53 | 
            +
                message: str
         | 
| 54 | 
            +
                output_path: str
         | 
| 55 | 
            +
                processing_time: float
         | 
| 56 | 
            +
                audio_generated: bool = False
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            class ElevenLabsClient:
         | 
| 59 | 
            +
                def __init__(self, api_key: str = None):
         | 
| 60 | 
            +
                    self.api_key = api_key or os.getenv("ELEVENLABS_API_KEY", "sk_c7a0b115cd48fc026226158c5ac87755b063c802ad892de6")
         | 
| 61 | 
            +
                    self.base_url = "https://api.elevenlabs.io/v1"
         | 
| 62 | 
            +
                    
         | 
| 63 | 
            +
                async def text_to_speech(self, text: str, voice_id: str = "21m00Tcm4TlvDq8ikWAM") -> str:
         | 
| 64 | 
            +
                    """Convert text to speech using ElevenLabs and return temporary file path"""
         | 
| 65 | 
            +
                    url = f"{self.base_url}/text-to-speech/{voice_id}"
         | 
| 66 | 
            +
                    
         | 
| 67 | 
            +
                    headers = {
         | 
| 68 | 
            +
                        "Accept": "audio/mpeg",
         | 
| 69 | 
            +
                        "Content-Type": "application/json",
         | 
| 70 | 
            +
                        "xi-api-key": self.api_key
         | 
| 71 | 
            +
                    }
         | 
| 72 | 
            +
                    
         | 
| 73 | 
            +
                    data = {
         | 
| 74 | 
            +
                        "text": text,
         | 
| 75 | 
            +
                        "model_id": "eleven_monolingual_v1",
         | 
| 76 | 
            +
                        "voice_settings": {
         | 
| 77 | 
            +
                            "stability": 0.5,
         | 
| 78 | 
            +
                            "similarity_boost": 0.5
         | 
| 79 | 
            +
                        }
         | 
| 80 | 
            +
                    }
         | 
| 81 | 
            +
                    
         | 
| 82 | 
            +
                    try:
         | 
| 83 | 
            +
                        async with aiohttp.ClientSession() as session:
         | 
| 84 | 
            +
                            async with session.post(url, headers=headers, json=data) as response:
         | 
| 85 | 
            +
                                if response.status != 200:
         | 
| 86 | 
            +
                                    error_text = await response.text()
         | 
| 87 | 
            +
                                    raise HTTPException(
         | 
| 88 | 
            +
                                        status_code=400, 
         | 
| 89 | 
            +
                                        detail=f"ElevenLabs API error: {response.status} - {error_text}"
         | 
| 90 | 
            +
                                    )
         | 
| 91 | 
            +
                                
         | 
| 92 | 
            +
                                audio_content = await response.read()
         | 
| 93 | 
            +
                                
         | 
| 94 | 
            +
                                # Save to temporary file
         | 
| 95 | 
            +
                                temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')
         | 
| 96 | 
            +
                                temp_file.write(audio_content)
         | 
| 97 | 
            +
                                temp_file.close()
         | 
| 98 | 
            +
                                
         | 
| 99 | 
            +
                                logger.info(f"Generated speech audio: {temp_file.name}")
         | 
| 100 | 
            +
                                return temp_file.name
         | 
| 101 | 
            +
                                
         | 
| 102 | 
            +
                    except aiohttp.ClientError as e:
         | 
| 103 | 
            +
                        logger.error(f"Network error calling ElevenLabs: {e}")
         | 
| 104 | 
            +
                        raise HTTPException(status_code=400, detail=f"Network error calling ElevenLabs: {e}")
         | 
| 105 | 
            +
                    except Exception as e:
         | 
| 106 | 
            +
                        logger.error(f"Error generating speech: {e}")
         | 
| 107 | 
            +
                        raise HTTPException(status_code=500, detail=f"Error generating speech: {e}")
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            class OmniAvatarAPI:
         | 
| 110 | 
            +
                def __init__(self):
         | 
| 111 | 
            +
                    self.model_loaded = False
         | 
| 112 | 
            +
                    self.device = "cuda" if torch.cuda.is_available() else "cpu"
         | 
| 113 | 
            +
                    self.elevenlabs_client = ElevenLabsClient()
         | 
| 114 | 
            +
                    logger.info(f"Using device: {self.device}")
         | 
| 115 | 
            +
                    logger.info(f"ElevenLabs API Key configured: {'Yes' if self.elevenlabs_client.api_key else 'No'}")
         | 
| 116 | 
            +
                    
         | 
| 117 | 
            +
                def load_model(self):
         | 
| 118 | 
            +
                    """Load the OmniAvatar model"""
         | 
| 119 | 
            +
                    try:
         | 
| 120 | 
            +
                        # Check if models are downloaded
         | 
| 121 | 
            +
                        model_paths = [
         | 
| 122 | 
            +
                            "./pretrained_models/Wan2.1-T2V-14B",
         | 
| 123 | 
            +
                            "./pretrained_models/OmniAvatar-14B", 
         | 
| 124 | 
            +
                            "./pretrained_models/wav2vec2-base-960h"
         | 
| 125 | 
            +
                        ]
         | 
| 126 | 
            +
                        
         | 
| 127 | 
            +
                        for path in model_paths:
         | 
| 128 | 
            +
                            if not os.path.exists(path):
         | 
| 129 | 
            +
                                logger.error(f"Model path not found: {path}")
         | 
| 130 | 
            +
                                return False
         | 
| 131 | 
            +
                                
         | 
| 132 | 
            +
                        self.model_loaded = True
         | 
| 133 | 
            +
                        logger.info("Models loaded successfully")
         | 
| 134 | 
            +
                        return True
         | 
| 135 | 
            +
                        
         | 
| 136 | 
            +
                    except Exception as e:
         | 
| 137 | 
            +
                        logger.error(f"Error loading model: {str(e)}")
         | 
| 138 | 
            +
                        return False
         | 
| 139 | 
            +
                
         | 
| 140 | 
            +
                async def download_file(self, url: str, suffix: str = "") -> str:
         | 
| 141 | 
            +
                    """Download file from URL and save to temporary location"""
         | 
| 142 | 
            +
                    try:
         | 
| 143 | 
            +
                        async with aiohttp.ClientSession() as session:
         | 
| 144 | 
            +
                            async with session.get(str(url)) as response:
         | 
| 145 | 
            +
                                if response.status != 200:
         | 
| 146 | 
            +
                                    raise HTTPException(status_code=400, detail=f"Failed to download file from URL: {url}")
         | 
| 147 | 
            +
                                
         | 
| 148 | 
            +
                                content = await response.read()
         | 
| 149 | 
            +
                                
         | 
| 150 | 
            +
                                # Create temporary file
         | 
| 151 | 
            +
                                temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
         | 
| 152 | 
            +
                                temp_file.write(content)
         | 
| 153 | 
            +
                                temp_file.close()
         | 
| 154 | 
            +
                                
         | 
| 155 | 
            +
                                return temp_file.name
         | 
| 156 | 
            +
                                
         | 
| 157 | 
            +
                    except aiohttp.ClientError as e:
         | 
| 158 | 
            +
                        logger.error(f"Network error downloading {url}: {e}")
         | 
| 159 | 
            +
                        raise HTTPException(status_code=400, detail=f"Network error downloading file: {e}")
         | 
| 160 | 
            +
                    except Exception as e:
         | 
| 161 | 
            +
                        logger.error(f"Error downloading file from {url}: {e}")
         | 
| 162 | 
            +
                        raise HTTPException(status_code=500, detail=f"Error downloading file: {e}")
         | 
| 163 | 
            +
                
         | 
| 164 | 
            +
                def validate_audio_url(self, url: str) -> bool:
         | 
| 165 | 
            +
                    """Validate if URL is likely an audio file"""
         | 
| 166 | 
            +
                    try:
         | 
| 167 | 
            +
                        parsed = urlparse(url)
         | 
| 168 | 
            +
                        # Check for common audio file extensions or ElevenLabs patterns
         | 
| 169 | 
            +
                        audio_extensions = ['.mp3', '.wav', '.m4a', '.ogg', '.aac']
         | 
| 170 | 
            +
                        is_audio_ext = any(parsed.path.lower().endswith(ext) for ext in audio_extensions)
         | 
| 171 | 
            +
                        is_elevenlabs = 'elevenlabs' in parsed.netloc.lower()
         | 
| 172 | 
            +
                        
         | 
| 173 | 
            +
                        return is_audio_ext or is_elevenlabs or 'audio' in url.lower()
         | 
| 174 | 
            +
                    except:
         | 
| 175 | 
            +
                        return False
         | 
| 176 | 
            +
                
         | 
| 177 | 
            +
                def validate_image_url(self, url: str) -> bool:
         | 
| 178 | 
            +
                    """Validate if URL is likely an image file"""
         | 
| 179 | 
            +
                    try:
         | 
| 180 | 
            +
                        parsed = urlparse(url)
         | 
| 181 | 
            +
                        image_extensions = ['.jpg', '.jpeg', '.png', '.webp', '.bmp', '.gif']
         | 
| 182 | 
            +
                        return any(parsed.path.lower().endswith(ext) for ext in image_extensions)
         | 
| 183 | 
            +
                    except:
         | 
| 184 | 
            +
                        return False
         | 
| 185 | 
            +
                
         | 
| 186 | 
            +
                async def generate_avatar(self, request: GenerateRequest) -> tuple[str, float, bool]:
         | 
| 187 | 
            +
                    """Generate avatar video from prompt and audio/text"""
         | 
| 188 | 
            +
                    import time
         | 
| 189 | 
            +
                    start_time = time.time()
         | 
| 190 | 
            +
                    audio_generated = False
         | 
| 191 | 
            +
                    
         | 
| 192 | 
            +
                    try:
         | 
| 193 | 
            +
                        # Determine audio source
         | 
| 194 | 
            +
                        audio_path = None
         | 
| 195 | 
            +
                        
         | 
| 196 | 
            +
                        if request.text_to_speech:
         | 
| 197 | 
            +
                            # Generate speech from text using ElevenLabs
         | 
| 198 | 
            +
                            logger.info(f"Generating speech from text: {request.text_to_speech[:50]}...")
         | 
| 199 | 
            +
                            audio_path = await self.elevenlabs_client.text_to_speech(
         | 
| 200 | 
            +
                                request.text_to_speech, 
         | 
| 201 | 
            +
                                request.voice_id or "21m00Tcm4TlvDq8ikWAM"
         | 
| 202 | 
            +
                            )
         | 
| 203 | 
            +
                            audio_generated = True
         | 
| 204 | 
            +
                            
         | 
| 205 | 
            +
                        elif request.elevenlabs_audio_url:
         | 
| 206 | 
            +
                            # Download audio from provided URL
         | 
| 207 | 
            +
                            logger.info(f"Downloading audio from URL: {request.elevenlabs_audio_url}")
         | 
| 208 | 
            +
                            if not self.validate_audio_url(str(request.elevenlabs_audio_url)):
         | 
| 209 | 
            +
                                logger.warning(f"Audio URL may not be valid: {request.elevenlabs_audio_url}")
         | 
| 210 | 
            +
                            
         | 
| 211 | 
            +
                            audio_path = await self.download_file(str(request.elevenlabs_audio_url), ".mp3")
         | 
| 212 | 
            +
                        
         | 
| 213 | 
            +
                        else:
         | 
| 214 | 
            +
                            raise HTTPException(
         | 
| 215 | 
            +
                                status_code=400, 
         | 
| 216 | 
            +
                                detail="Either text_to_speech or elevenlabs_audio_url must be provided"
         | 
| 217 | 
            +
                            )
         | 
| 218 | 
            +
                        
         | 
| 219 | 
            +
                        # Download image if provided
         | 
| 220 | 
            +
                        image_path = None
         | 
| 221 | 
            +
                        if request.image_url:
         | 
| 222 | 
            +
                            logger.info(f"Downloading image from URL: {request.image_url}")
         | 
| 223 | 
            +
                            if not self.validate_image_url(str(request.image_url)):
         | 
| 224 | 
            +
                                logger.warning(f"Image URL may not be valid: {request.image_url}")
         | 
| 225 | 
            +
                            
         | 
| 226 | 
            +
                            # Determine image extension from URL or default to .jpg
         | 
| 227 | 
            +
                            parsed = urlparse(str(request.image_url))
         | 
| 228 | 
            +
                            ext = os.path.splitext(parsed.path)[1] or ".jpg"
         | 
| 229 | 
            +
                            image_path = await self.download_file(str(request.image_url), ext)
         | 
| 230 | 
            +
                        
         | 
| 231 | 
            +
                        # Create temporary input file for inference
         | 
| 232 | 
            +
                        with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
         | 
| 233 | 
            +
                            if image_path:
         | 
| 234 | 
            +
                                input_line = f"{request.prompt}@@{image_path}@@{audio_path}"
         | 
| 235 | 
            +
                            else:
         | 
| 236 | 
            +
                                input_line = f"{request.prompt}@@@@{audio_path}"
         | 
| 237 | 
            +
                            f.write(input_line)
         | 
| 238 | 
            +
                            temp_input_file = f.name
         | 
| 239 | 
            +
                        
         | 
| 240 | 
            +
                        # Prepare inference command
         | 
| 241 | 
            +
                        cmd = [
         | 
| 242 | 
            +
                            "python", "-m", "torch.distributed.run",
         | 
| 243 | 
            +
                            "--standalone", f"--nproc_per_node={request.sp_size}",
         | 
| 244 | 
            +
                            "scripts/inference.py",
         | 
| 245 | 
            +
                            "--config", "configs/inference.yaml",
         | 
| 246 | 
            +
                            "--input_file", temp_input_file,
         | 
| 247 | 
            +
                            "--guidance_scale", str(request.guidance_scale),
         | 
| 248 | 
            +
                            "--audio_scale", str(request.audio_scale),
         | 
| 249 | 
            +
                            "--num_steps", str(request.num_steps)
         | 
| 250 | 
            +
                        ]
         | 
| 251 | 
            +
                        
         | 
| 252 | 
            +
                        if request.tea_cache_l1_thresh:
         | 
| 253 | 
            +
                            cmd.extend(["--tea_cache_l1_thresh", str(request.tea_cache_l1_thresh)])
         | 
| 254 | 
            +
                        
         | 
| 255 | 
            +
                        logger.info(f"Running inference with command: {' '.join(cmd)}")
         | 
| 256 | 
            +
                        
         | 
| 257 | 
            +
                        # Run inference
         | 
| 258 | 
            +
                        result = subprocess.run(cmd, capture_output=True, text=True)
         | 
| 259 | 
            +
                        
         | 
| 260 | 
            +
                        # Clean up temporary files
         | 
| 261 | 
            +
                        os.unlink(temp_input_file)
         | 
| 262 | 
            +
                        os.unlink(audio_path)
         | 
| 263 | 
            +
                        if image_path:
         | 
| 264 | 
            +
                            os.unlink(image_path)
         | 
| 265 | 
            +
                        
         | 
| 266 | 
            +
                        if result.returncode != 0:
         | 
| 267 | 
            +
                            logger.error(f"Inference failed: {result.stderr}")
         | 
| 268 | 
            +
                            raise Exception(f"Inference failed: {result.stderr}")
         | 
| 269 | 
            +
                        
         | 
| 270 | 
            +
                        # Find output video file
         | 
| 271 | 
            +
                        output_dir = "./outputs"
         | 
| 272 | 
            +
                        if os.path.exists(output_dir):
         | 
| 273 | 
            +
                            video_files = [f for f in os.listdir(output_dir) if f.endswith(('.mp4', '.avi'))]
         | 
| 274 | 
            +
                            if video_files:
         | 
| 275 | 
            +
                                # Return the most recent video file
         | 
| 276 | 
            +
                                video_files.sort(key=lambda x: os.path.getmtime(os.path.join(output_dir, x)), reverse=True)
         | 
| 277 | 
            +
                                output_path = os.path.join(output_dir, video_files[0])
         | 
| 278 | 
            +
                                processing_time = time.time() - start_time
         | 
| 279 | 
            +
                                return output_path, processing_time, audio_generated
         | 
| 280 | 
            +
                        
         | 
| 281 | 
            +
                        raise Exception("No output video generated")
         | 
| 282 | 
            +
                        
         | 
| 283 | 
            +
                    except Exception as e:
         | 
| 284 | 
            +
                        # Clean up any temporary files in case of error
         | 
| 285 | 
            +
                        try:
         | 
| 286 | 
            +
                            if 'audio_path' in locals() and audio_path and os.path.exists(audio_path):
         | 
| 287 | 
            +
                                os.unlink(audio_path)
         | 
| 288 | 
            +
                            if 'image_path' in locals() and image_path and os.path.exists(image_path):
         | 
| 289 | 
            +
                                os.unlink(image_path)
         | 
| 290 | 
            +
                            if 'temp_input_file' in locals() and os.path.exists(temp_input_file):
         | 
| 291 | 
            +
                                os.unlink(temp_input_file)
         | 
| 292 | 
            +
                        except:
         | 
| 293 | 
            +
                            pass
         | 
| 294 | 
            +
                        
         | 
| 295 | 
            +
                        logger.error(f"Generation error: {str(e)}")
         | 
| 296 | 
            +
                        raise HTTPException(status_code=500, detail=str(e))
         | 
| 297 | 
            +
             | 
| 298 | 
            +
            # Initialize API
         | 
| 299 | 
            +
            omni_api = OmniAvatarAPI()
         | 
| 300 | 
            +
             | 
| 301 | 
            +
            @app.on_event("startup")
         | 
| 302 | 
            +
            async def startup_event():
         | 
| 303 | 
            +
                """Load model on startup"""
         | 
| 304 | 
            +
                success = omni_api.load_model()
         | 
| 305 | 
            +
                if not success:
         | 
| 306 | 
            +
                    logger.warning("Model loading failed on startup")
         | 
| 307 | 
            +
             | 
| 308 | 
            +
            @app.get("/health")
         | 
| 309 | 
            +
            async def health_check():
         | 
| 310 | 
            +
                """Health check endpoint"""
         | 
| 311 | 
            +
                return {
         | 
| 312 | 
            +
                    "status": "healthy",
         | 
| 313 | 
            +
                    "model_loaded": omni_api.model_loaded,
         | 
| 314 | 
            +
                    "device": omni_api.device,
         | 
| 315 | 
            +
                    "supports_elevenlabs": True,
         | 
| 316 | 
            +
                    "supports_image_urls": True,
         | 
| 317 | 
            +
                    "supports_text_to_speech": True,
         | 
| 318 | 
            +
                    "elevenlabs_api_configured": bool(omni_api.elevenlabs_client.api_key)
         | 
| 319 | 
            +
                }
         | 
| 320 | 
            +
             | 
| 321 | 
            +
            @app.post("/generate", response_model=GenerateResponse)
         | 
| 322 | 
            +
            async def generate_avatar(request: GenerateRequest):
         | 
| 323 | 
            +
                """Generate avatar video from prompt, text/audio, and optional image URL"""
         | 
| 324 | 
            +
                
         | 
| 325 | 
            +
                if not omni_api.model_loaded:
         | 
| 326 | 
            +
                    raise HTTPException(status_code=503, detail="Model not loaded")
         | 
| 327 | 
            +
                
         | 
| 328 | 
            +
                logger.info(f"Generating avatar with prompt: {request.prompt}")
         | 
| 329 | 
            +
                if request.text_to_speech:
         | 
| 330 | 
            +
                    logger.info(f"Text to speech: {request.text_to_speech[:100]}...")
         | 
| 331 | 
            +
                    logger.info(f"Voice ID: {request.voice_id}")
         | 
| 332 | 
            +
                if request.elevenlabs_audio_url:
         | 
| 333 | 
            +
                    logger.info(f"Audio URL: {request.elevenlabs_audio_url}")
         | 
| 334 | 
            +
                if request.image_url:
         | 
| 335 | 
            +
                    logger.info(f"Image URL: {request.image_url}")
         | 
| 336 | 
            +
                
         | 
| 337 | 
            +
                try:
         | 
| 338 | 
            +
                    output_path, processing_time, audio_generated = await omni_api.generate_avatar(request)
         | 
| 339 | 
            +
                    
         | 
| 340 | 
            +
                    return GenerateResponse(
         | 
| 341 | 
            +
                        message="Avatar generation completed successfully",
         | 
| 342 | 
            +
                        output_path=output_path,
         | 
| 343 | 
            +
                        processing_time=processing_time,
         | 
| 344 | 
            +
                        audio_generated=audio_generated
         | 
| 345 | 
            +
                    )
         | 
| 346 | 
            +
                    
         | 
| 347 | 
            +
                except HTTPException:
         | 
| 348 | 
            +
                    raise
         | 
| 349 | 
            +
                except Exception as e:
         | 
| 350 | 
            +
                    logger.error(f"Unexpected error: {e}")
         | 
| 351 | 
            +
                    raise HTTPException(status_code=500, detail=f"Unexpected error: {e}")
         | 
| 352 | 
            +
             | 
| 353 | 
            +
            # Enhanced Gradio interface with text-to-speech option
         | 
| 354 | 
            +
            def gradio_generate(prompt, text_to_speech, audio_url, image_url, voice_id, guidance_scale, audio_scale, num_steps):
         | 
| 355 | 
            +
                """Gradio interface wrapper with text-to-speech support"""
         | 
| 356 | 
            +
                if not omni_api.model_loaded:
         | 
| 357 | 
            +
                    return "Error: Model not loaded"
         | 
| 358 | 
            +
                
         | 
| 359 | 
            +
                try:
         | 
| 360 | 
            +
                    # Create request object
         | 
| 361 | 
            +
                    request_data = {
         | 
| 362 | 
            +
                        "prompt": prompt,
         | 
| 363 | 
            +
                        "guidance_scale": guidance_scale,
         | 
| 364 | 
            +
                        "audio_scale": audio_scale,
         | 
| 365 | 
            +
                        "num_steps": int(num_steps)
         | 
| 366 | 
            +
                    }
         | 
| 367 | 
            +
                    
         | 
| 368 | 
            +
                    # Add audio source
         | 
| 369 | 
            +
                    if text_to_speech and text_to_speech.strip():
         | 
| 370 | 
            +
                        request_data["text_to_speech"] = text_to_speech
         | 
| 371 | 
            +
                        request_data["voice_id"] = voice_id or "21m00Tcm4TlvDq8ikWAM"
         | 
| 372 | 
            +
                    elif audio_url and audio_url.strip():
         | 
| 373 | 
            +
                        request_data["elevenlabs_audio_url"] = audio_url
         | 
| 374 | 
            +
                    else:
         | 
| 375 | 
            +
                        return "Error: Please provide either text to speech or audio URL"
         | 
| 376 | 
            +
                    
         | 
| 377 | 
            +
                    if image_url and image_url.strip():
         | 
| 378 | 
            +
                        request_data["image_url"] = image_url
         | 
| 379 | 
            +
                    
         | 
| 380 | 
            +
                    request = GenerateRequest(**request_data)
         | 
| 381 | 
            +
                    
         | 
| 382 | 
            +
                    # Run async function in sync context
         | 
| 383 | 
            +
                    loop = asyncio.new_event_loop()
         | 
| 384 | 
            +
                    asyncio.set_event_loop(loop)
         | 
| 385 | 
            +
                    output_path, processing_time, audio_generated = loop.run_until_complete(omni_api.generate_avatar(request))
         | 
| 386 | 
            +
                    loop.close()
         | 
| 387 | 
            +
                    
         | 
| 388 | 
            +
                    return output_path
         | 
| 389 | 
            +
                    
         | 
| 390 | 
            +
                except Exception as e:
         | 
| 391 | 
            +
                    logger.error(f"Gradio generation error: {e}")
         | 
| 392 | 
            +
                    return f"Error: {str(e)}"
         | 
| 393 | 
            +
             | 
| 394 | 
            +
            # Updated Gradio interface with text-to-speech support
         | 
| 395 | 
            +
            iface = gr.Interface(
         | 
| 396 | 
            +
                fn=gradio_generate,
         | 
| 397 | 
            +
                inputs=[
         | 
| 398 | 
            +
                    gr.Textbox(
         | 
| 399 | 
            +
                        label="Prompt", 
         | 
| 400 | 
            +
                        placeholder="Describe the character behavior (e.g., 'A friendly person explaining a concept')",
         | 
| 401 | 
            +
                        lines=2
         | 
| 402 | 
            +
                    ),
         | 
| 403 | 
            +
                    gr.Textbox(
         | 
| 404 | 
            +
                        label="Text to Speech", 
         | 
| 405 | 
            +
                        placeholder="Enter text to convert to speech using ElevenLabs",
         | 
| 406 | 
            +
                        lines=3,
         | 
| 407 | 
            +
                        info="This will be converted to speech automatically"
         | 
| 408 | 
            +
                    ),
         | 
| 409 | 
            +
                    gr.Textbox(
         | 
| 410 | 
            +
                        label="OR Audio URL", 
         | 
| 411 | 
            +
                        placeholder="https://api.elevenlabs.io/v1/text-to-speech/...",
         | 
| 412 | 
            +
                        info="Direct URL to audio file (alternative to text-to-speech)"
         | 
| 413 | 
            +
                    ),
         | 
| 414 | 
            +
                    gr.Textbox(
         | 
| 415 | 
            +
                        label="Image URL (Optional)", 
         | 
| 416 | 
            +
                        placeholder="https://example.com/image.jpg",
         | 
| 417 | 
            +
                        info="Direct URL to reference image (JPG, PNG, etc.)"
         | 
| 418 | 
            +
                    ),
         | 
| 419 | 
            +
                    gr.Dropdown(
         | 
| 420 | 
            +
                        choices=["21m00Tcm4TlvDq8ikWAM", "pNInz6obpgDQGcFmaJgB", "EXAVITQu4vr4xnSDxMaL"],
         | 
| 421 | 
            +
                        value="21m00Tcm4TlvDq8ikWAM",
         | 
| 422 | 
            +
                        label="ElevenLabs Voice ID",
         | 
| 423 | 
            +
                        info="Choose voice for text-to-speech"
         | 
| 424 | 
            +
                    ),
         | 
| 425 | 
            +
                    gr.Slider(minimum=1, maximum=10, value=5.0, label="Guidance Scale", info="4-6 recommended"),
         | 
| 426 | 
            +
                    gr.Slider(minimum=1, maximum=10, value=3.0, label="Audio Scale", info="Higher values = better lip-sync"),
         | 
| 427 | 
            +
                    gr.Slider(minimum=10, maximum=100, value=30, step=1, label="Number of Steps", info="20-50 recommended")
         | 
| 428 | 
            +
                ],
         | 
| 429 | 
            +
                outputs=gr.Video(label="Generated Avatar Video"),
         | 
| 430 | 
            +
                title="🎭 OmniAvatar-14B with ElevenLabs TTS",
         | 
| 431 | 
            +
                description="""
         | 
| 432 | 
            +
                Generate avatar videos with lip-sync from text prompts and speech.
         | 
| 433 | 
            +
                
         | 
| 434 | 
            +
                **Features:**
         | 
| 435 | 
            +
                - ✅ **Text-to-Speech**: Enter text to generate speech automatically
         | 
| 436 | 
            +
                - ✅ **ElevenLabs Integration**: High-quality voice synthesis  
         | 
| 437 | 
            +
                - ✅ **Audio URL Support**: Use pre-generated audio files
         | 
| 438 | 
            +
                - ✅ **Image URL Support**: Reference images for character appearance
         | 
| 439 | 
            +
                - ✅ **Customizable Parameters**: Fine-tune generation quality
         | 
| 440 | 
            +
                
         | 
| 441 | 
            +
                **Usage:**
         | 
| 442 | 
            +
                1. Enter a character description in the prompt
         | 
| 443 | 
            +
                2. **Either** enter text for speech generation **OR** provide an audio URL
         | 
| 444 | 
            +
                3. Optionally add a reference image URL
         | 
| 445 | 
            +
                4. Choose voice and adjust parameters
         | 
| 446 | 
            +
                5. Generate your avatar video!
         | 
| 447 | 
            +
                
         | 
| 448 | 
            +
                **Tips:**
         | 
| 449 | 
            +
                - Use guidance scale 4-6 for best prompt following
         | 
| 450 | 
            +
                - Increase audio scale for better lip-sync
         | 
| 451 | 
            +
                - Clear, descriptive prompts work best
         | 
| 452 | 
            +
                """,
         | 
| 453 | 
            +
                examples=[
         | 
| 454 | 
            +
                    [
         | 
| 455 | 
            +
                        "A professional teacher explaining a mathematical concept with clear gestures",
         | 
| 456 | 
            +
                        "Hello students! Today we're going to learn about calculus and how derivatives work in real life.",
         | 
| 457 | 
            +
                        "",
         | 
| 458 | 
            +
                        "https://example.com/teacher.jpg",
         | 
| 459 | 
            +
                        "21m00Tcm4TlvDq8ikWAM",
         | 
| 460 | 
            +
                        5.0,
         | 
| 461 | 
            +
                        3.5,
         | 
| 462 | 
            +
                        30
         | 
| 463 | 
            +
                    ],
         | 
| 464 | 
            +
                    [
         | 
| 465 | 
            +
                        "A friendly presenter speaking confidently to an audience",
         | 
| 466 | 
            +
                        "Welcome everyone to our presentation on artificial intelligence and its applications!",
         | 
| 467 | 
            +
                        "",
         | 
| 468 | 
            +
                        "",
         | 
| 469 | 
            +
                        "pNInz6obpgDQGcFmaJgB", 
         | 
| 470 | 
            +
                        5.5,
         | 
| 471 | 
            +
                        4.0,
         | 
| 472 | 
            +
                        35
         | 
| 473 | 
            +
                    ]
         | 
| 474 | 
            +
                ]
         | 
| 475 | 
            +
            )
         | 
| 476 | 
            +
             | 
| 477 | 
            +
            # Mount Gradio app
         | 
| 478 | 
            +
            app = gr.mount_gradio_app(app, iface, path="/gradio")
         | 
| 479 | 
            +
             | 
| 480 | 
            +
            if __name__ == "__main__":
         | 
| 481 | 
            +
                import uvicorn
         | 
| 482 | 
            +
                uvicorn.run(app, host="0.0.0.0", port=7860)
         | 
    	
        get_voices.ps1
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Script to get ElevenLabs voice IDs
         | 
| 2 | 
            +
            Write-Host "Getting ElevenLabs Voice IDs..." -ForegroundColor Yellow
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # You'll need your ElevenLabs API key for this
         | 
| 5 | 
            +
            $apiKey = Read-Host "Enter your ElevenLabs API Key (or press Enter to skip)"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            if ($apiKey) {
         | 
| 8 | 
            +
                try {
         | 
| 9 | 
            +
                    $headers = @{
         | 
| 10 | 
            +
                        "xi-api-key" = $apiKey
         | 
| 11 | 
            +
                        "Content-Type" = "application/json"
         | 
| 12 | 
            +
                    }
         | 
| 13 | 
            +
                    
         | 
| 14 | 
            +
                    $response = Invoke-RestMethod -Uri "https://api.elevenlabs.io/v1/voices" -Headers $headers -Method GET
         | 
| 15 | 
            +
                    
         | 
| 16 | 
            +
                    Write-Host "`n✅ Available Voices:" -ForegroundColor Green
         | 
| 17 | 
            +
                    foreach ($voice in $response.voices) {
         | 
| 18 | 
            +
                        Write-Host "Name: $($voice.name)" -ForegroundColor Cyan
         | 
| 19 | 
            +
                        Write-Host "ID: $($voice.voice_id)" -ForegroundColor White
         | 
| 20 | 
            +
                        Write-Host "Category: $($voice.category)" -ForegroundColor Gray
         | 
| 21 | 
            +
                        Write-Host "Description: $($voice.description)" -ForegroundColor Gray
         | 
| 22 | 
            +
                        Write-Host "---" -ForegroundColor DarkGray
         | 
| 23 | 
            +
                    }
         | 
| 24 | 
            +
                } catch {
         | 
| 25 | 
            +
                    Write-Host "❌ Error getting voices: $($_.Exception.Message)" -ForegroundColor Red
         | 
| 26 | 
            +
                }
         | 
| 27 | 
            +
            } else {
         | 
| 28 | 
            +
                Write-Host "Skipping API call - showing default voice IDs instead" -ForegroundColor Yellow
         | 
| 29 | 
            +
            }
         | 
    	
        hf_tts_client.py
    ADDED
    
    | @@ -0,0 +1,115 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            import torch
         | 
| 2 | 
            +
            import tempfile
         | 
| 3 | 
            +
            import logging
         | 
| 4 | 
            +
            import soundfile as sf
         | 
| 5 | 
            +
            import numpy as np
         | 
| 6 | 
            +
            from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
         | 
| 7 | 
            +
            from datasets import load_dataset
         | 
| 8 | 
            +
            import asyncio
         | 
| 9 | 
            +
            from typing import Optional
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            logger = logging.getLogger(__name__)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            class HuggingFaceTTSClient:
         | 
| 14 | 
            +
                """
         | 
| 15 | 
            +
                Hugging Face TTS client using Microsoft SpeechT5
         | 
| 16 | 
            +
                Replaces ElevenLabs with free, open-source TTS
         | 
| 17 | 
            +
                """
         | 
| 18 | 
            +
                
         | 
| 19 | 
            +
                def __init__(self):
         | 
| 20 | 
            +
                    self.device = "cuda" if torch.cuda.is_available() else "cpu"
         | 
| 21 | 
            +
                    self.processor = None
         | 
| 22 | 
            +
                    self.model = None
         | 
| 23 | 
            +
                    self.vocoder = None
         | 
| 24 | 
            +
                    self.speaker_embeddings = None
         | 
| 25 | 
            +
                    self.model_loaded = False
         | 
| 26 | 
            +
                    
         | 
| 27 | 
            +
                    logger.info(f"HF TTS Client initialized on device: {self.device}")
         | 
| 28 | 
            +
                    
         | 
| 29 | 
            +
                async def load_model(self):
         | 
| 30 | 
            +
                    """Load SpeechT5 model and vocoder"""
         | 
| 31 | 
            +
                    try:
         | 
| 32 | 
            +
                        logger.info("Loading SpeechT5 TTS model...")
         | 
| 33 | 
            +
                        
         | 
| 34 | 
            +
                        # Load processor, model and vocoder
         | 
| 35 | 
            +
                        self.processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
         | 
| 36 | 
            +
                        self.model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts").to(self.device)
         | 
| 37 | 
            +
                        self.vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(self.device)
         | 
| 38 | 
            +
                        
         | 
| 39 | 
            +
                        # Load speaker embeddings dataset
         | 
| 40 | 
            +
                        embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
         | 
| 41 | 
            +
                        self.speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0).to(self.device)
         | 
| 42 | 
            +
                        
         | 
| 43 | 
            +
                        self.model_loaded = True
         | 
| 44 | 
            +
                        logger.info("✅ SpeechT5 TTS model loaded successfully")
         | 
| 45 | 
            +
                        return True
         | 
| 46 | 
            +
                        
         | 
| 47 | 
            +
                    except Exception as e:
         | 
| 48 | 
            +
                        logger.error(f"❌ Failed to load TTS model: {e}")
         | 
| 49 | 
            +
                        return False
         | 
| 50 | 
            +
                
         | 
| 51 | 
            +
                async def text_to_speech(self, text: str, voice_id: Optional[str] = None) -> str:
         | 
| 52 | 
            +
                    """
         | 
| 53 | 
            +
                    Convert text to speech using SpeechT5
         | 
| 54 | 
            +
                    
         | 
| 55 | 
            +
                    Args:
         | 
| 56 | 
            +
                        text: Text to convert to speech
         | 
| 57 | 
            +
                        voice_id: Voice identifier (for compatibility, maps to speaker embeddings)
         | 
| 58 | 
            +
                        
         | 
| 59 | 
            +
                    Returns:
         | 
| 60 | 
            +
                        Path to generated audio file
         | 
| 61 | 
            +
                    """
         | 
| 62 | 
            +
                    if not self.model_loaded:
         | 
| 63 | 
            +
                        logger.info("Model not loaded, loading now...")
         | 
| 64 | 
            +
                        success = await self.load_model()
         | 
| 65 | 
            +
                        if not success:
         | 
| 66 | 
            +
                            raise Exception("Failed to load TTS model")
         | 
| 67 | 
            +
                    
         | 
| 68 | 
            +
                    try:
         | 
| 69 | 
            +
                        logger.info(f"Generating speech for text: {text[:50]}...")
         | 
| 70 | 
            +
                        
         | 
| 71 | 
            +
                        # Choose speaker embedding based on voice_id (for variety)
         | 
| 72 | 
            +
                        speaker_idx = self._get_speaker_index(voice_id)
         | 
| 73 | 
            +
                        embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
         | 
| 74 | 
            +
                        speaker_embeddings = torch.tensor(embeddings_dataset[speaker_idx]["xvector"]).unsqueeze(0).to(self.device)
         | 
| 75 | 
            +
                        
         | 
| 76 | 
            +
                        # Process text
         | 
| 77 | 
            +
                        inputs = self.processor(text=text, return_tensors="pt").to(self.device)
         | 
| 78 | 
            +
                        
         | 
| 79 | 
            +
                        # Generate speech
         | 
| 80 | 
            +
                        with torch.no_grad():
         | 
| 81 | 
            +
                            speech = self.model.generate_speech(
         | 
| 82 | 
            +
                                inputs["input_ids"], 
         | 
| 83 | 
            +
                                speaker_embeddings, 
         | 
| 84 | 
            +
                                vocoder=self.vocoder
         | 
| 85 | 
            +
                            )
         | 
| 86 | 
            +
                        
         | 
| 87 | 
            +
                        # Convert to audio file
         | 
| 88 | 
            +
                        audio_data = speech.cpu().numpy()
         | 
| 89 | 
            +
                        
         | 
| 90 | 
            +
                        # Save to temporary file
         | 
| 91 | 
            +
                        temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.wav')
         | 
| 92 | 
            +
                        sf.write(temp_file.name, audio_data, samplerate=16000)
         | 
| 93 | 
            +
                        temp_file.close()
         | 
| 94 | 
            +
                        
         | 
| 95 | 
            +
                        logger.info(f"✅ Generated speech audio: {temp_file.name}")
         | 
| 96 | 
            +
                        return temp_file.name
         | 
| 97 | 
            +
                        
         | 
| 98 | 
            +
                    except Exception as e:
         | 
| 99 | 
            +
                        logger.error(f"❌ Error generating speech: {e}")
         | 
| 100 | 
            +
                        raise Exception(f"TTS generation failed: {e}")
         | 
| 101 | 
            +
                
         | 
| 102 | 
            +
                def _get_speaker_index(self, voice_id: Optional[str]) -> int:
         | 
| 103 | 
            +
                    """Map voice_id to speaker embedding index for voice variety"""
         | 
| 104 | 
            +
                    voice_mapping = {
         | 
| 105 | 
            +
                        # Map ElevenLabs voice IDs to speaker indices for compatibility
         | 
| 106 | 
            +
                        "21m00Tcm4TlvDq8ikWAM": 7306,  # Female voice (default)
         | 
| 107 | 
            +
                        "pNInz6obpgDQGcFmaJgB": 4077,  # Male voice  
         | 
| 108 | 
            +
                        "EXAVITQu4vr4xnSDxMaL": 1995,  # Female voice (sweet)
         | 
| 109 | 
            +
                        "ErXwobaYiN019PkySvjV": 8051,  # Male voice (professional)
         | 
| 110 | 
            +
                        "TxGEqnHWrfWFTfGW9XjX": 5688,  # Deep male voice
         | 
| 111 | 
            +
                        "yoZ06aMxZJJ28mfd3POQ": 3570,  # Friendly voice
         | 
| 112 | 
            +
                        "AZnzlk1XvdvUeBnXmlld": 2967,  # Strong female
         | 
| 113 | 
            +
                    }
         | 
| 114 | 
            +
                    
         | 
| 115 | 
            +
                    return voice_mapping.get(voice_id, 7306)  # Default to female voice
         | 
    	
        requirements.txt
    CHANGED
    
    | @@ -42,3 +42,11 @@ python-dotenv>=1.0.0 | |
| 42 | 
             
            # Additional dependencies for HF Spaces
         | 
| 43 | 
             
            huggingface-hub>=0.17.0
         | 
| 44 | 
             
            safetensors>=0.4.0
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 42 | 
             
            # Additional dependencies for HF Spaces
         | 
| 43 | 
             
            huggingface-hub>=0.17.0
         | 
| 44 | 
             
            safetensors>=0.4.0
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            # Hugging Face TTS (replacing ElevenLabs)
         | 
| 47 | 
            +
            transformers>=4.21.0
         | 
| 48 | 
            +
            torch>=2.0.0
         | 
| 49 | 
            +
            torchaudio>=2.0.0
         | 
| 50 | 
            +
            speechbrain>=0.5.0
         | 
| 51 | 
            +
            datasets>=2.0.0
         | 
| 52 | 
            +
            soundfile>=0.12.0
         | 
    	
        test_api.ps1
    ADDED
    
    | @@ -0,0 +1,31 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Test your HF Space API
         | 
| 2 | 
            +
            $baseUrl = "https://bravedims-ai-avatar-chat.hf.space"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Write-Host "Testing HF Space API..." -ForegroundColor Yellow
         | 
| 5 | 
            +
            Write-Host "Base URL: $baseUrl" -ForegroundColor Cyan
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            # Test health endpoint
         | 
| 8 | 
            +
            try {
         | 
| 9 | 
            +
                Write-Host "`nTesting health endpoint..." -ForegroundColor Green
         | 
| 10 | 
            +
                $healthResponse = Invoke-RestMethod -Uri "$baseUrl/health" -Method GET -TimeoutSec 30
         | 
| 11 | 
            +
                Write-Host "✅ Health Check Response:" -ForegroundColor Green
         | 
| 12 | 
            +
                $healthResponse | ConvertTo-Json -Depth 3
         | 
| 13 | 
            +
            } catch {
         | 
| 14 | 
            +
                Write-Host "❌ Health check failed: $($_.Exception.Message)" -ForegroundColor Red
         | 
| 15 | 
            +
                Write-Host "This might mean the Space is still building or not running yet." -ForegroundColor Yellow
         | 
| 16 | 
            +
            }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            # Test if Space exists (even if not running)
         | 
| 19 | 
            +
            try {
         | 
| 20 | 
            +
                Write-Host "`nTesting if Space URL exists..." -ForegroundColor Green
         | 
| 21 | 
            +
                $response = Invoke-WebRequest -Uri $baseUrl -Method GET -TimeoutSec 30 -ErrorAction SilentlyContinue
         | 
| 22 | 
            +
                Write-Host "✅ Space URL is accessible (Status: $($response.StatusCode))" -ForegroundColor Green
         | 
| 23 | 
            +
            } catch {
         | 
| 24 | 
            +
                Write-Host "❌ Space URL not accessible: $($_.Exception.Message)" -ForegroundColor Red
         | 
| 25 | 
            +
            }
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            Write-Host "`n📋 Your API Information:" -ForegroundColor Magenta
         | 
| 28 | 
            +
            Write-Host "Base URL: $baseUrl" -ForegroundColor White
         | 
| 29 | 
            +
            Write-Host "Health: GET $baseUrl/health" -ForegroundColor White  
         | 
| 30 | 
            +
            Write-Host "Generate: POST $baseUrl/generate" -ForegroundColor White
         | 
| 31 | 
            +
            Write-Host "Gradio UI: $baseUrl/gradio" -ForegroundColor White
         | 
    	
        test_audio_url.ps1
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Test using direct audio URL instead of text-to-speech
         | 
| 2 | 
            +
            Write-Host "🔄 Testing with direct audio URL (bypassing ElevenLabs)..." -ForegroundColor Yellow
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            $audioTestPayload = @{
         | 
| 5 | 
            +
                prompt = "A professional teacher explaining a mathematical concept with clear gestures"
         | 
| 6 | 
            +
                elevenlabs_audio_url = "https://www.soundjay.com/misc/sounds/bell-ringing-05.wav"
         | 
| 7 | 
            +
                image_url = "https://i.ibb.co/8g4xryvS/531bd0d0c48b.png"
         | 
| 8 | 
            +
                guidance_scale = 5.0
         | 
| 9 | 
            +
                audio_scale = 3.5
         | 
| 10 | 
            +
                num_steps = 30
         | 
| 11 | 
            +
            } | ConvertTo-Json -Depth 3
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            Write-Host "Testing with audio URL instead of TTS..." -ForegroundColor Cyan
         | 
| 14 | 
            +
            Write-Host $audioTestPayload -ForegroundColor Gray
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            try {
         | 
| 17 | 
            +
                $headers = @{"Content-Type" = "application/json"}
         | 
| 18 | 
            +
                $response = Invoke-RestMethod -Uri "https://bravedims-ai-avatar-chat.hf.space/generate" -Method POST -Body $audioTestPayload -Headers $headers -TimeoutSec 120
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                Write-Host "✅ Success with audio URL!" -ForegroundColor Green
         | 
| 21 | 
            +
                $response | ConvertTo-Json -Depth 3
         | 
| 22 | 
            +
            } catch {
         | 
| 23 | 
            +
                Write-Host "❌ Still failing: $($_.Exception.Message)" -ForegroundColor Red
         | 
| 24 | 
            +
            }
         | 
    	
        test_elevenlabs.ps1
    ADDED
    
    | @@ -0,0 +1,50 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Test ElevenLabs API directly
         | 
| 2 | 
            +
            Write-Host "🧪 Testing ElevenLabs API Integration..." -ForegroundColor Yellow
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # Test 1: Check if your API is accessible
         | 
| 5 | 
            +
            try {
         | 
| 6 | 
            +
                Write-Host "`n1. Testing API health..." -ForegroundColor Cyan
         | 
| 7 | 
            +
                $health = Invoke-RestMethod -Uri "https://bravedims-ai-avatar-chat.hf.space/health" -Method GET
         | 
| 8 | 
            +
                Write-Host "✅ API Status: $($health.status)" -ForegroundColor Green
         | 
| 9 | 
            +
                Write-Host "✅ ElevenLabs Configured: $($health.elevenlabs_api_configured)" -ForegroundColor Green
         | 
| 10 | 
            +
            } catch {
         | 
| 11 | 
            +
                Write-Host "❌ API Health Check Failed: $($_.Exception.Message)" -ForegroundColor Red
         | 
| 12 | 
            +
            }
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            # Test 2: Try a simple generate request with better voice ID
         | 
| 15 | 
            +
            try {
         | 
| 16 | 
            +
                Write-Host "`n2. Testing generation with Rachel voice (most reliable)..." -ForegroundColor Cyan
         | 
| 17 | 
            +
                
         | 
| 18 | 
            +
                $testPayload = @{
         | 
| 19 | 
            +
                    prompt = "A simple test"
         | 
| 20 | 
            +
                    text_to_speech = "This is a test message."
         | 
| 21 | 
            +
                    voice_id = "21m00Tcm4TlvDq8ikWAM"
         | 
| 22 | 
            +
                    guidance_scale = 5.0
         | 
| 23 | 
            +
                    audio_scale = 3.5
         | 
| 24 | 
            +
                    num_steps = 20
         | 
| 25 | 
            +
                } | ConvertTo-Json -Depth 3
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                Write-Host "Payload:" -ForegroundColor Gray
         | 
| 28 | 
            +
                Write-Host $testPayload -ForegroundColor White
         | 
| 29 | 
            +
                
         | 
| 30 | 
            +
                $headers = @{"Content-Type" = "application/json"}
         | 
| 31 | 
            +
                $response = Invoke-RestMethod -Uri "https://bravedims-ai-avatar-chat.hf.space/generate" -Method POST -Body $testPayload -Headers $headers -TimeoutSec 120
         | 
| 32 | 
            +
                
         | 
| 33 | 
            +
                Write-Host "✅ Generation successful!" -ForegroundColor Green
         | 
| 34 | 
            +
                $response | ConvertTo-Json -Depth 3
         | 
| 35 | 
            +
                
         | 
| 36 | 
            +
            } catch {
         | 
| 37 | 
            +
                Write-Host "❌ Generation failed: $($_.Exception.Message)" -ForegroundColor Red
         | 
| 38 | 
            +
                if ($_.Exception.Response) {
         | 
| 39 | 
            +
                    Write-Host "Status Code: $($_.Exception.Response.StatusCode)" -ForegroundColor Yellow
         | 
| 40 | 
            +
                    $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
         | 
| 41 | 
            +
                    $responseBody = $reader.ReadToEnd()
         | 
| 42 | 
            +
                    Write-Host "Response Body: $responseBody" -ForegroundColor Yellow
         | 
| 43 | 
            +
                }
         | 
| 44 | 
            +
            }
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            Write-Host "`n📋 Common ElevenLabs Issues:" -ForegroundColor Magenta
         | 
| 47 | 
            +
            Write-Host "1. API Key expired or invalid" -ForegroundColor White
         | 
| 48 | 
            +
            Write-Host "2. Voice ID doesn't exist in your account" -ForegroundColor White  
         | 
| 49 | 
            +
            Write-Host "3. Rate limit exceeded" -ForegroundColor White
         | 
| 50 | 
            +
            Write-Host "4. Account credit/quota exhausted" -ForegroundColor White
         | 
    	
        test_fixes.ps1
    ADDED
    
    | @@ -0,0 +1,18 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Test the health endpoint to check API key status
         | 
| 2 | 
            +
            Write-Host "Testing API after fixes..." -ForegroundColor Yellow
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            try {
         | 
| 5 | 
            +
                $healthResponse = Invoke-RestMethod -Uri "https://bravedims-ai-avatar-chat.hf.space/health" -Method GET -TimeoutSec 30
         | 
| 6 | 
            +
                Write-Host "✅ Health Check Response:" -ForegroundColor Green
         | 
| 7 | 
            +
                $healthResponse | ConvertTo-Json -Depth 3
         | 
| 8 | 
            +
                
         | 
| 9 | 
            +
                # Check if ElevenLabs is properly configured
         | 
| 10 | 
            +
                if ($healthResponse.elevenlabs_api_configured -eq $true) {
         | 
| 11 | 
            +
                    Write-Host "`n✅ ElevenLabs API is configured!" -ForegroundColor Green
         | 
| 12 | 
            +
                } else {
         | 
| 13 | 
            +
                    Write-Host "`n❌ ElevenLabs API key still not configured" -ForegroundColor Red
         | 
| 14 | 
            +
                    Write-Host "👉 You need to add ELEVENLABS_API_KEY to your HF Space secrets" -ForegroundColor Yellow
         | 
| 15 | 
            +
                }
         | 
| 16 | 
            +
            } catch {
         | 
| 17 | 
            +
                Write-Host "❌ Error: $($_.Exception.Message)" -ForegroundColor Red
         | 
| 18 | 
            +
            }
         | 
    	
        test_generate.ps1
    ADDED
    
    | @@ -0,0 +1,31 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Test the generate endpoint with your JSON
         | 
| 2 | 
            +
            $apiUrl = "https://bravedims-ai-avatar-chat.hf.space/generate"
         | 
| 3 | 
            +
            $jsonPayload = @{
         | 
| 4 | 
            +
                prompt = "A professional teacher explaining a mathematical concept with clear gestures"
         | 
| 5 | 
            +
                text_to_speech = "Hello students! Today we're going to learn about calculus and how derivatives work in real life."
         | 
| 6 | 
            +
                voice_id = "21m00Tcm4TlvDq8ikWAM"
         | 
| 7 | 
            +
                image_url = "https://example.com/teacher.jpg"
         | 
| 8 | 
            +
                guidance_scale = 5.0
         | 
| 9 | 
            +
                audio_scale = 3.5
         | 
| 10 | 
            +
                num_steps = 30
         | 
| 11 | 
            +
            } | ConvertTo-Json -Depth 3
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            $headers = @{
         | 
| 14 | 
            +
                "Content-Type" = "application/json"
         | 
| 15 | 
            +
            }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Write-Host "Testing generate endpoint..." -ForegroundColor Yellow
         | 
| 18 | 
            +
            Write-Host "URL: $apiUrl" -ForegroundColor Cyan
         | 
| 19 | 
            +
            Write-Host "Payload:" -ForegroundColor Green
         | 
| 20 | 
            +
            Write-Host $jsonPayload -ForegroundColor White
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            try {
         | 
| 23 | 
            +
                $response = Invoke-RestMethod -Uri $apiUrl -Method POST -Body $jsonPayload -Headers $headers -TimeoutSec 120
         | 
| 24 | 
            +
                Write-Host "`n✅ Success! Response:" -ForegroundColor Green
         | 
| 25 | 
            +
                $response | ConvertTo-Json -Depth 3
         | 
| 26 | 
            +
            } catch {
         | 
| 27 | 
            +
                Write-Host "`n❌ Error: $($_.Exception.Message)" -ForegroundColor Red
         | 
| 28 | 
            +
                if ($_.Exception.Response) {
         | 
| 29 | 
            +
                    Write-Host "Status Code: $($_.Exception.Response.StatusCode)" -ForegroundColor Yellow
         | 
| 30 | 
            +
                }
         | 
| 31 | 
            +
            }
         | 
    	
        test_hf_tts.py
    ADDED
    
    | @@ -0,0 +1,23 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # Test script for HuggingFace TTS
         | 
| 2 | 
            +
            import asyncio
         | 
| 3 | 
            +
            import logging
         | 
| 4 | 
            +
            from hf_tts_client import HuggingFaceTTSClient
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            logging.basicConfig(level=logging.INFO)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            async def test_hf_tts():
         | 
| 9 | 
            +
                print("🧪 Testing HuggingFace TTS Client...")
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                client = HuggingFaceTTSClient()
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                try:
         | 
| 14 | 
            +
                    # Test TTS generation
         | 
| 15 | 
            +
                    audio_path = await client.text_to_speech("Hello, this is a test of HuggingFace TTS!")
         | 
| 16 | 
            +
                    print(f"✅ TTS Success! Audio saved to: {audio_path}")
         | 
| 17 | 
            +
                    return True
         | 
| 18 | 
            +
                except Exception as e:
         | 
| 19 | 
            +
                    print(f"❌ TTS Failed: {e}")
         | 
| 20 | 
            +
                    return False
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            if __name__ == "__main__":
         | 
| 23 | 
            +
                asyncio.run(test_hf_tts())
         | 
    	
        voice_ids_reference.txt
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            # ElevenLabs Voice ID Reference
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ## ✅ Ready-to-Use Voice IDs:
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            **Most Popular (Rachel - Clear Female):**
         | 
| 6 | 
            +
            21m00Tcm4TlvDq8ikWAM
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            **Professional Male (Adam):**  
         | 
| 9 | 
            +
            pNInz6obpgDQGcFmaJgB
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            **Professional Male (Antoni):**
         | 
| 12 | 
            +
            ErXwobaYiN019PkySvjV
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            **Sweet Female (Bella):**
         | 
| 15 | 
            +
            EXAVITQu4vr4xnSDxMaL
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            **Deep Male (Josh):**
         | 
| 18 | 
            +
            TxGEqnHWrfWFTfGW9XjX
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            **Friendly Male (Sam):**
         | 
| 21 | 
            +
            yoZ06aMxZJJ28mfd3POQ
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            **Strong Female (Domi):**
         | 
| 24 | 
            +
            AZnzlk1XvdvUeBnXmlld
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            ## 🧪 Test Your API with Different Voices:
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            1. Rachel (Default): "21m00Tcm4TlvDq8ikWAM" 
         | 
| 29 | 
            +
            2. Adam (Professional): "pNInz6obpgDQGcFmaJgB"
         | 
| 30 | 
            +
            3. Bella (Sweet): "EXAVITQu4vr4xnSDxMaL"
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            Just copy any of these IDs into your API request!
         | 
