Spaces:
Runtime error
Runtime error
Canstralian
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,23 @@
|
|
1 |
from gradio import components as gc
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
#
|
12 |
-
|
|
|
13 |
|
14 |
-
# Create the interface
|
15 |
iface = gr.Interface(
|
16 |
fn=greet,
|
17 |
inputs="text",
|
@@ -20,7 +26,9 @@ iface = gr.Interface(
|
|
20 |
description="Ask a user for their name and greet them."
|
21 |
)
|
22 |
|
23 |
-
#
|
|
|
|
|
24 |
iface.add_component(sidebar, side="left")
|
25 |
|
26 |
# Launch the Gradio app
|
|
|
1 |
from gradio import components as gc
|
2 |
import gradio as gr
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
|
5 |
+
# Load model and tokenizer
|
6 |
+
model_name = "Canstralian/CySec_Known_Exploit_Analyzer"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Define the function for text input processing
|
11 |
+
def greet(text):
|
12 |
+
# Tokenize and process the input text
|
13 |
+
inputs = tokenizer(text, return_tensors="pt")
|
14 |
+
outputs = model(**inputs)
|
15 |
|
16 |
+
# Extract the label with the highest score
|
17 |
+
predicted_label = outputs.logits.argmax().item()
|
18 |
+
return f"Greeting, {text}! Predicted label: {predicted_label}"
|
19 |
|
20 |
+
# Create the interface
|
21 |
iface = gr.Interface(
|
22 |
fn=greet,
|
23 |
inputs="text",
|
|
|
26 |
description="Ask a user for their name and greet them."
|
27 |
)
|
28 |
|
29 |
+
# Optional: define and add a sidebar if needed
|
30 |
+
# Example sidebar component (replace with your intended content)
|
31 |
+
sidebar = gr.Textbox(label="Sidebar Info")
|
32 |
iface.add_component(sidebar, side="left")
|
33 |
|
34 |
# Launch the Gradio app
|