darshankr commited on
Commit
cec381a
·
verified ·
1 Parent(s): 4deff0c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a sentiment analysis model from Hugging Face Hub
5
+ model = pipeline("sentiment-analysis")
6
+
7
+ # API function to analyze sentiment
8
+ def analyze(text: str):
9
+ result = model(text)
10
+ return result
11
+
12
+ # Define the Gradio Interface (this will act as an API)
13
+ iface = gr.Interface(
14
+ fn=analyze,
15
+ inputs=gr.Textbox(label="Input Text"),
16
+ outputs="json" # JSON output for API-like response
17
+ )
18
+
19
+ # Launch the Gradio app (this exposes the API)
20
+ iface.launch()