Alexa17 commited on
Commit
aa81d8f
verified
1 Parent(s): 0201bd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -1,28 +1,25 @@
1
- from fastapi import FastAPI, HTTPException
2
- from pydantic import BaseModel
3
- from typing import List
4
 
5
- class InputData(BaseModel):
6
- data: List[float] # Lista de caracter铆sticas num茅ricas (flotantes)
7
 
8
- app = FastAPI()
 
 
 
 
9
 
10
- def sumar(a,b):
11
- return a+b
 
 
 
 
 
 
 
 
 
 
12
 
13
- # Ruta de predicci贸n
14
- @app.post("/predict/")
15
- async def predict(data: InputData):
16
- print(f"Data: {data}")
17
- try:
18
- # Convertir la lista de entrada a un array de NumPy para la predicci贸n
19
- input_data = data.data
20
- print(input_data)
21
- a = input_data[0]
22
- b = input_data[1]
23
- c = sumar(a,b)
24
- prediction = c
25
- #return {"prediction": prediction.tolist()}
26
- return {"prediction": prediction}
27
- except Exception as e:
28
- raise HTTPException(status_code=500, detail=str(e))
 
1
+ import gradio as gr
2
+ from transformers import pipeline
 
3
 
4
+ # Cargar el modelo de Hugging Face para an谩lisis de emociones
5
+ classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-large")
6
 
7
+ # Funci贸n para predecir la emoci贸n
8
+ def detect_emotion(text):
9
+ result = classifier(text)
10
+ emotion = result[0]['label']
11
+ return emotion
12
 
13
+ # Crear la interfaz con Gradio
14
+ interface = gr.Interface(
15
+ fn=detect_emotion,
16
+ inputs="text",
17
+ outputs="text",
18
+ live=True,
19
+ title="Detector de Emociones",
20
+ description="Introduce un texto para detectar la emoci贸n que expresa."
21
+ )
22
+
23
+ # Lanzar la interfaz
24
+ interface.launch()
25