EmreCaylar commited on
Commit
4201593
·
1 Parent(s): fbdc35c

app update

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -1,19 +1,21 @@
1
  import gradio as gr
2
- from fastapi import FastAPI
3
- import uvicorn
4
 
5
- # Create a FastAPI app
6
- app = FastAPI()
7
 
8
- # Create Gradio interface (just like in Hugging Face Spaces)
9
  def classify_emotion(text):
10
- # Your model code here (replace this with the actual classification)
11
- return "happy" # example return value
12
 
13
- gradio_interface = gr.Interface(fn=classify_emotion, inputs="text", outputs="text")
 
 
 
 
 
 
14
 
15
- # Mount the Gradio app inside FastAPI
16
- app.mount("/gradio", gradio_interface)
17
-
18
- if __name__ == "__main__":
19
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
3
 
4
+ # Load the BERT-Emotions-Classifier model
5
+ classifier = pipeline("text-classification", model="ayoubkirouane/BERT-Emotions-Classifier")
6
 
7
+ # Define the prediction function for emotion classification
8
  def classify_emotion(text):
9
+ result = classifier(text)
10
+ return result[0]['label'], result[0]['score']
11
 
12
+ # Define the Gradio interface
13
+ iface = gr.Interface(
14
+ fn=classify_emotion, # function that will classify emotion
15
+ inputs=gr.Textbox(), # input text box
16
+ outputs=[gr.Textbox(), gr.Textbox()], # output emotion label and score
17
+ live=True # Enable live mode (optional)
18
+ )
19
 
20
+ # Launch the Gradio interface as an API
21
+ iface.launch(share=True)