Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
API_URL = "https://api-inference.huggingface.co/models/gabehubner/trained-distilbert-model"
|
| 6 |
+
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
| 7 |
+
|
| 8 |
+
def classify_text(text):
|
| 9 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": text})
|
| 10 |
+
if response.status_code != 200:
|
| 11 |
+
return f"Error: {response.text}"
|
| 12 |
+
|
| 13 |
+
results = response.json()
|
| 14 |
+
return f"Label: {results[0]['label']} (Confidence: {results[0]['score']:.2f})"
|
| 15 |
+
|
| 16 |
+
interface = gr.Interface(
|
| 17 |
+
fn=classify_text,
|
| 18 |
+
inputs=gr.Textbox(placeholder="Enter text here..."),
|
| 19 |
+
outputs="text",
|
| 20 |
+
title="Sentiment Classifier",
|
| 21 |
+
description="Enter text and see whether it's classified as positive or negative!",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
interface.launch()
|