marcela9409 commited on
Commit
9338a37
1 Parent(s): c49fc60

Improve code

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -1,23 +1,10 @@
1
  import gradio as gr
2
- import requests
3
- from numpy import asarray
4
- import tensorflow as tf
5
  from transformers import pipeline
6
 
7
- inception_net = tf.keras.applications.MobileNetV2()
8
- answer = requests.get("https://git.io/JJkYN")
9
- labels =answer.text.split("\n")
10
-
11
  transcribe = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish")
12
  classifier = pipeline("text-classification", model = "pysentimiento/robertuito-sentiment-analysis")
13
-
14
- def classify_image(inp):
15
- inp = asarray(inp.resize((224, 224)))
16
- inp = inp.reshape((-1,) + inp.shape)
17
- inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
18
- prediction = inception_net.predict(inp).flatten()
19
- confidences = {labels[k]: float(prediction[k]) for k in range(1000)}
20
- return confidences
21
 
22
  def audio_to_text(audio):
23
  text = transcribe(audio)["text"]
@@ -25,7 +12,13 @@ def audio_to_text(audio):
25
 
26
  def text_to_sentiment(text):
27
  return classifier(text)[0]["label"]
28
-
 
 
 
 
 
 
29
  demo = gr.Blocks()
30
 
31
  with demo:
 
1
  import gradio as gr
2
+ from PIL import Image
 
 
3
  from transformers import pipeline
4
 
 
 
 
 
5
  transcribe = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish")
6
  classifier = pipeline("text-classification", model = "pysentimiento/robertuito-sentiment-analysis")
7
+ image_classifier = pipeline("image-classification", model="microsoft/swin-tiny-patch4-window7-224")
 
 
 
 
 
 
 
8
 
9
  def audio_to_text(audio):
10
  text = transcribe(audio)["text"]
 
12
 
13
  def text_to_sentiment(text):
14
  return classifier(text)[0]["label"]
15
+
16
+ def classify_image(image):
17
+ image = Image.fromarray(image.astype('uint8'), 'RGB')
18
+ answers = image_classifier(image)
19
+ labels = {answer["label"]: answer["score"] for answer in answers}
20
+ return labels
21
+
22
  demo = gr.Blocks()
23
 
24
  with demo: