|
import gradio as gr |
|
from transformers import pipeline |
|
import requests |
|
import json |
|
import os |
|
|
|
def speechToText(file): |
|
|
|
api_key = os.getenv("veni18sttts") |
|
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo" |
|
headers = {"Authorization": f"Bearer {api_key}"} |
|
|
|
def query(file): |
|
with open(file, "rb") as f: |
|
data = f.read() |
|
response = requests.post(API_URL, headers=headers, data=data) |
|
return response.json() |
|
|
|
my_text = query(file) |
|
|
|
sentences = my_text["text"].split(".") |
|
|
|
|
|
def translate(sentences): |
|
translation = pipeline("translation", model="Helsinki-NLP/opus-mt-en-hu") |
|
|
|
text_translated=[] |
|
for text in sentences: |
|
text_translated.append(translation(text)) |
|
|
|
return text_translated |
|
|
|
text_translate = translate(sentences) |
|
|
|
|
|
|
|
return text_translate |
|
|
|
demo = gr.Interface(fn=speechToText, inputs="file", outputs="text") |
|
demo.launch() |