Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +37 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import mindsdb_sdk
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Connect to cloud server
|
| 8 |
+
email = os.environ.get('email')
|
| 9 |
+
passw = os.environ.get('passw')
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# Connect to MindsDB Pro
|
| 13 |
+
|
| 14 |
+
server = mindsdb_sdk.connect('https://cloud.mindsdb.com', login=email, password=passw, is_managed=True)
|
| 15 |
+
project = server.get_project("mindsdb")
|
| 16 |
+
model = project.list_models()[0]
|
| 17 |
+
|
| 18 |
+
def classify_text(text):
|
| 19 |
+
# Classify text using the loaded model
|
| 20 |
+
var = {"Text": text}
|
| 21 |
+
data = pd.DataFrame(var, index=[0])
|
| 22 |
+
result = model.predict(data)
|
| 23 |
+
label = result['topic']
|
| 24 |
+
score = result['score']
|
| 25 |
+
return f"Label: {label}"
|
| 26 |
+
|
| 27 |
+
# Create Gradio interface
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=classify_text,
|
| 30 |
+
inputs=gr.inputs.Textbox(label="Enter text to classify"),
|
| 31 |
+
outputs="text",
|
| 32 |
+
title="Identify spoiler comments with zero-shot text classification",
|
| 33 |
+
description="Input a sentence here"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Launch the interface
|
| 37 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mindsdb_sdk
|
| 2 |
+
pandas
|