fajjos commited on
Commit
64984fe
·
1 Parent(s): 0990774

Add application file

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ # Load the model and tokenizer from Hugging Face
6
+ model_name = "fajjos/keyword_variable_detection_v1"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
+
10
+ # Streamlit UI
11
+ st.title("Keyword and Variable Extraction")
12
+ st.write("Instruction: Extract keywords and variables from the prompt.")
13
+
14
+ # Input for user text
15
+ user_input = st.text_area("Input Text", "University of Oxford timeshigher ranking")
16
+
17
+ if st.button("Predict"):
18
+ # Tokenize the input
19
+ inputs = tokenizer(user_input, return_tensors="pt")
20
+
21
+ # Run inference
22
+ with torch.no_grad():
23
+ outputs = model(**inputs)
24
+
25
+ # Process the outputs
26
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
27
+ predicted_class = predictions.argmax().item()
28
+
29
+ st.write(f"Predicted class: {predicted_class}, Confidence: {predictions[0][predicted_class]:.2f}")