Spaces:
Runtime error
Runtime error
acecalisto3
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,26 @@ import torch
|
|
28 |
import mysql.connector
|
29 |
from mysql.connector import errorcode, pooling
|
30 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Load environment variables from .env file
|
33 |
load_dotenv()
|
|
|
28 |
import mysql.connector
|
29 |
from mysql.connector import errorcode, pooling
|
30 |
from dotenv import load_dotenv
|
31 |
+
from huggingface_hub import login
|
32 |
+
|
33 |
+
# Initialize a zero-shot classification pipeline
|
34 |
+
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
35 |
+
|
36 |
+
def parse_command(message):
|
37 |
+
candidate_labels = ["filter", "sort", "export", "log"]
|
38 |
+
result = classifier(message, candidate_labels)
|
39 |
+
return result['labels'][0] if result['scores'][0] > 0.5 else None
|
40 |
+
|
41 |
+
# Usage
|
42 |
+
command = parse_command("Filter apples, oranges in column Description")
|
43 |
+
print(command) # Output: 'filter'
|
44 |
+
|
45 |
+
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
46 |
+
if not HUGGINGFACE_TOKEN:
|
47 |
+
raise ValueError("HUGGINGFACE_TOKEN is not set in the environment variables.")
|
48 |
+
|
49 |
+
login(token=HUGGINGFACE_TOKEN)
|
50 |
+
|
51 |
|
52 |
# Load environment variables from .env file
|
53 |
load_dotenv()
|