|
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) |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
def summa(my_text): |
|
pipe = pipeline("summarization", model="facebook/bart-large-cnn") |
|
|
|
max = 1024 |
|
if len(my_text) > max: |
|
combined_text_parts = [my_text[i:i + max] for i in range(0, len(my_text), max)] |
|
else: |
|
combined_text_parts = [my_text] |
|
|
|
summaries = [] |
|
for part in combined_text_parts: |
|
summary = pipe(part, max_length=180, min_length=140, do_sample=False) |
|
summaries.append(summary[0]['summary_text']) |
|
|
|
|
|
full_summary = ' '.join(summaries) |
|
|
|
|
|
return full_summary |
|
|
|
full_summaries = summa(my_text["text"]) |
|
|
|
return full_summaries |
|
|
|
demo = gr.Interface(fn=speechToText, inputs="file", outputs="text") |
|
demo.launch() |