Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load model
|
| 5 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 6 |
|
|
|
|
| 7 |
def analyze(text):
|
| 8 |
result = sentiment_pipeline(text)
|
| 9 |
-
return
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
interface = gr.Interface(
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the sentiment analysis model
|
| 5 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 6 |
|
| 7 |
+
# Function to analyze text input
|
| 8 |
def analyze(text):
|
| 9 |
result = sentiment_pipeline(text)
|
| 10 |
+
return {
|
| 11 |
+
"label": result[0]['label'],
|
| 12 |
+
"score": result[0]['score']
|
| 13 |
+
}
|
| 14 |
|
| 15 |
+
# Create a Gradio interface
|
| 16 |
+
interface = gr.Interface(
|
| 17 |
+
fn=analyze, # Function to call
|
| 18 |
+
inputs="text", # Input type
|
| 19 |
+
outputs="json", # Output type (JSON for API compatibility)
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Launch with API sharing
|
| 23 |
+
interface.launch(share=True) # Ensure share=True for Hugging Face Spaces
|