import gradio as gr import torch from transformers import T5ForConditionalGeneration,T5Tokenizer import soundfile as sf import librosa from transformers import pipeline import requests import json API_TOKEN = 'your-api-token' # 你在Hugging Face网站上的API令牌 API_URL = 'https://api-inference.huggingface.co/models/gpt2' # 根据你的模型选择合适的URL headers = { "Authorization": f"Bearer {API_TOKEN}", } def generate(inp): data = json.dumps({"inputs": inp}) response = requests.request("POST", API_URL, headers=headers, data=data) return json.loads(response.content.decode("utf-8"))[0]['generated_text'] iface = gr.Interface( fn=generate, inputs=gr.inputs.Textbox(lines=5, label="Input Text"), outputs="text", title="Text-to-Speech", description="Convert your text into speech!", ) iface.launch()