File size: 934 Bytes
cdf962c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import tensorflow as tf
import requests
from numpy import asarray
from transformers import pipeline

inception_net = tf.keras.applications.MobileNetV2()

# Obteniendo las labels de "https://git.io/JJkYN"
response = requests.get("https://git.io/JJkYN")
labels = response.text.split("\n")

trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
clasificador = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")

def classify_image(inp):
  inp = asarray(inp.resize((224, 224)))
  inp = inp.reshape((-1,) + inp.shape)
  inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
  prediction = inception_net.predict(inp).flatten()
  confidences = {labels[k]: float(prediction[k]) for k in range(1000)}
  return confidences

def audio2text(audio):
  text = trans(audio)["text"]
  return text

def text2sentiment(text):
  return clasificador(text)[0]["label"]