Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def load_model():
|
| 5 |
# Load a pre-trained HuggingFace pipeline for sentiment analysis
|
| 6 |
model_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
|
@@ -11,13 +17,19 @@ def classify_text(model, text):
|
|
| 11 |
result = model(text)
|
| 12 |
return result
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def main():
|
| 15 |
# Load the model
|
| 16 |
model = load_model()
|
| 17 |
|
| 18 |
# Define the Gradio interface
|
| 19 |
interface = gr.Interface(
|
| 20 |
-
fn=lambda text:
|
| 21 |
inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),
|
| 22 |
outputs="json",
|
| 23 |
title="Text Classification with HuggingFace",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Azure Text Analytics setup
|
| 5 |
+
azure_endpoint = "https://t6langservice.cognitiveservices.azure.com/"
|
| 6 |
+
azure_api_key = "3CU1gpUszvl7pLb90Ivdp1Kd5WZc56savzdXOK5GV40JHebnxnxoJQQJ99BAACYeBjFXJ3w3AAAaACOGkRT5"
|
| 7 |
+
# Authenticate client
|
| 8 |
+
text_analytics_client = TextAnalyticsClient(endpoint=azure_endpoint, credential=AzureKeyCredential(azure_api_key))
|
| 9 |
+
|
| 10 |
def load_model():
|
| 11 |
# Load a pre-trained HuggingFace pipeline for sentiment analysis
|
| 12 |
model_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
|
|
|
| 17 |
result = model(text)
|
| 18 |
return result
|
| 19 |
|
| 20 |
+
|
| 21 |
+
def classify_text_azure(model, text):
|
| 22 |
+
# Use the loaded model to classify text
|
| 23 |
+
result = text_analytics_client.analyze_sentiment(text)
|
| 24 |
+
return result
|
| 25 |
+
|
| 26 |
def main():
|
| 27 |
# Load the model
|
| 28 |
model = load_model()
|
| 29 |
|
| 30 |
# Define the Gradio interface
|
| 31 |
interface = gr.Interface(
|
| 32 |
+
fn=lambda text: classify_text_azure(model, text),
|
| 33 |
inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),
|
| 34 |
outputs="json",
|
| 35 |
title="Text Classification with HuggingFace",
|