imranjamal commited on
Commit
4c14fd4
·
verified ·
1 Parent(s): 45e64df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
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 f"Label: {result[0]['label']}, Score: {result[0]['score']}"
 
 
 
10
 
11
- # Interface
12
- interface = gr.Interface(fn=analyze, inputs="text", outputs="text")
13
- interface.launch()
 
 
 
 
 
 
 
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