Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
# Load the model and tokenizer | |
model_name = "suno/bark-small" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
# Define the Gradio interface | |
def text_to_speech(text): | |
# Tokenize the input text | |
inputs = tokenizer.encode(text, return_tensors="pt") | |
# Generate speech from the input text using the loaded model | |
outputs = model.generate(inputs) | |
# Convert the generated speech tensor to audio format | |
speech = gradio.inputs.Audio(outputs) | |
return speech | |
# Create the Gradio interface | |
iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio", | |
title="Text-to-Speech App", | |
description="Enter text to hear the speech") | |
# Launch the Gradio interface | |
iface.launch() | |