Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
# Inicialize o cliente com o modelo do Hugging Face
|
5 |
client = InferenceClient(model="ulisesbravo/autotrain-nsuej-5ctie")
|
6 |
|
7 |
def classify_text(text):
|
8 |
-
# Realize a inferência chamando o método post
|
9 |
-
|
10 |
|
11 |
-
#
|
12 |
-
|
|
|
13 |
|
14 |
-
#
|
|
|
|
|
|
|
15 |
if isinstance(response, list) and len(response) > 0:
|
16 |
-
|
|
|
|
|
17 |
else:
|
18 |
predicted_class = "Classificação não encontrada"
|
19 |
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import json
|
4 |
|
5 |
# Inicialize o cliente com o modelo do Hugging Face
|
6 |
client = InferenceClient(model="ulisesbravo/autotrain-nsuej-5ctie")
|
7 |
|
8 |
def classify_text(text):
|
9 |
+
# Realize a inferência chamando o método post
|
10 |
+
response_bytes = client.post(json={"inputs": text}) # Enviar o texto
|
11 |
|
12 |
+
# Decodificar a resposta de bytes para string e depois para JSON
|
13 |
+
response_str = response_bytes.decode('utf-8') # Decodificar de bytes para string
|
14 |
+
response = json.loads(response_str) # Converter string JSON para um objeto Python
|
15 |
|
16 |
+
# Inspecionar a resposta para depuração
|
17 |
+
print(response)
|
18 |
+
|
19 |
+
# Verificar se a resposta é uma lista válida
|
20 |
if isinstance(response, list) and len(response) > 0:
|
21 |
+
# Ordenar as classificações pelo score e pegar a de maior valor
|
22 |
+
sorted_response = sorted(response[0], key=lambda x: x['score'], reverse=True)
|
23 |
+
predicted_class = sorted_response[0]['label'] # Pegar a classe com maior score
|
24 |
else:
|
25 |
predicted_class = "Classificação não encontrada"
|
26 |
|