Leonel Valencia commited on
Commit
cdf962c
Β·
verified Β·
1 Parent(s): 71a9cef

Create functions.py

Browse files
Files changed (1) hide show
  1. functions.py +28 -0
functions.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import requests
3
+ from numpy import asarray
4
+ from transformers import pipeline
5
+
6
+ inception_net = tf.keras.applications.MobileNetV2()
7
+
8
+ # Obteniendo las labels de "https://git.io/JJkYN"
9
+ response = requests.get("https://git.io/JJkYN")
10
+ labels = response.text.split("\n")
11
+
12
+ trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
13
+ clasificador = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
14
+
15
+ def classify_image(inp):
16
+ inp = asarray(inp.resize((224, 224)))
17
+ inp = inp.reshape((-1,) + inp.shape)
18
+ inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
19
+ prediction = inception_net.predict(inp).flatten()
20
+ confidences = {labels[k]: float(prediction[k]) for k in range(1000)}
21
+ return confidences
22
+
23
+ def audio2text(audio):
24
+ text = trans(audio)["text"]
25
+ return text
26
+
27
+ def text2sentiment(text):
28
+ return clasificador(text)[0]["label"]