Canstralian commited on
Commit
56f2045
·
verified ·
1 Parent(s): 23c859c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -1,17 +1,23 @@
1
  from gradio import components as gc
2
  import gradio as gr
 
3
 
4
- # Create a sidebar component
5
- sidebar = gc.SideBar()
6
- for item in sidebar_items:
7
- prompt_button = gc.Button(text=item["prompt"])
8
- description = item["description"]
9
- # Add additional styling or functionality if needed
 
 
 
 
10
 
11
- # Append the button and description to the sidebar component
12
- sidebar.append(prompt_button, description)
 
13
 
14
- # Create the interface without a sidebar (since we've added it separately)
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
- # Add the left sidebar to the interface
 
 
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