Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /upload_sample route to allow upload new speakers using Web API #80

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

abeiro
Copy link

@abeiro abeiro commented Jun 11, 2024

  • Added route to upload sample into speakers folder, so you can upload new speakers using API
  • Added python-multipart to requirements

Summary by CodeRabbit

  • New Features

    • Introduced a new endpoint for uploading WAV files, which saves the file and returns the filename.
    • Added a Jupyter Notebook for a comprehensive setup guide to deploy the AI text-to-speech server using the X-TTS API.
  • Chores

    • Updated .gitignore to exclude modules-xtts.txt from version control.
  • Dependencies

    • Added python-multipart package to support file uploads.

…d new speakers using API

* Added python-multipart to requirements
Copy link
Contributor

coderabbitai bot commented Jun 11, 2024

Walkthrough

The recent update modifies the .gitignore file by adding modules-xtts.txt to the list of ignored files. This change ensures that modules-xtts.txt will now be excluded from version control, while no other entries in the .gitignore file were altered.

Changes

Files Change Summary
.gitignore Added modules-xtts.txt to the list of ignored files.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant VersionControl

    Developer->>VersionControl: Add modules-xtts.txt to .gitignore
    VersionControl-->>Developer: modules-xtts.txt ignored
Loading

Poem

In the code's embrace, a file takes flight,
Ignored now, it dances out of sight.
With .gitignore as a gentle guide,
Modules tucked away, no need to hide.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 47d3568 and 571c4f2.

⛔ Files ignored due to path filters (1)
  • speakers/TheNarrator.wav is excluded by !**/*.wav
📒 Files selected for processing (1)
  • .gitignore (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range and nitpick comments (2)
xtts_api_server/server.py (2)

Line range hint 195-195: Improve exception handling by using exception chaining.

- raise HTTPException(status_code=400, detail=str(e))
+ raise HTTPException(status_code=400, detail=str(e)) from e

Also applies to: 204-204, 224-224, 233-233, 298-298, 329-329, 353-353

Tools
Ruff

1-1: TTS.api.TTS imported but unused (F401)

Remove unused import: TTS.api.TTS


Line range hint 150-150: Avoid redefining the get_speakers function.

- @app.get("/speakers")
+ @app.get("/special_speakers")
  def get_speakers_special():
Tools
Ruff

1-1: TTS.api.TTS imported but unused (F401)

Remove unused import: TTS.api.TTS

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8285ecd and 98845ca.

Files selected for processing (2)
  • requirements.txt (1 hunks)
  • xtts_api_server/server.py (2 hunks)
Files skipped from review due to trivial changes (1)
  • requirements.txt
Additional context used
Ruff
xtts_api_server/server.py

1-1: TTS.api.TTS imported but unused (F401)

Remove unused import: TTS.api.TTS


10-10: time imported but unused (F401)

Remove unused import: time


12-12: shutil imported but unused (F401)

Remove unused import: shutil


14-14: argparse.ArgumentParser imported but unused (F401)

Remove unused import: argparse.ArgumentParser


15-15: Redefinition of unused Path from line 11 (F811)

Remove definition: Path


150-150: Redefinition of unused get_speakers from line 145 (F811)


195-195: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling (B904)


204-204: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling (B904)


207-207: Do not perform function call File in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable (B008)


224-224: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling (B904)


233-233: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling (B904)


298-298: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling (B904)


329-329: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling (B904)


353-353: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling (B904)

@@ -1,5 +1,5 @@
from TTS.api import TTS
from fastapi import BackgroundTasks, FastAPI, HTTPException, Request, Query
from fastapi import BackgroundTasks, FastAPI, HTTPException, Request, Query, File, UploadFile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports to clean up the code.

- from TTS.api import TTS
- import time
- import shutil
- from argparse import ArgumentParser
- from pathlib import Path

Committable suggestion was skipped due to low confidence.

@@ -203,6 +203,17 @@ def set_speaker_folder(speaker_req: SpeakerFolderRequest):
logger.error(e)
raise HTTPException(status_code=400, detail=str(e))

@app.post("/upload_sample")
async def upload_sample(wavFile: UploadFile = File(...)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using File(...) as a default argument.

- async def upload_sample(wavFile: UploadFile = File(...)):
+ async def upload_sample(wavFile: UploadFile = None):
+     if wavFile is None:
+         wavFile = File(...)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async def upload_sample(wavFile: UploadFile = File(...)):
async def upload_sample(wavFile: UploadFile = None):
if wavFile is None:
wavFile = File(...)
Tools
Ruff

207-207: Do not perform function call File in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable (B008)

@daswer123
Copy link
Owner

Great, thanks, I'll take a look tomorrow.
I've been trying to add it myself but haven't had the time )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants