fajjos commited on
Commit
7cefe7c
·
1 Parent(s): b5a099c

Add Streamlit app and requirements

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForTokenClassification, AutoTokenizer
3
+ import torch
4
+
5
+ # Load the model and tokenizer from Hugging Face
6
+ model_name = "fajjos/Keyword_v1" # Replace with the actual model name
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForTokenClassification.from_pretrained(model_name)
9
+
10
+ # Streamlit interface
11
+ st.title("Keyword Extractor")
12
+ user_input = st.text_area("Enter text for keyword extraction")
13
+
14
+ if user_input:
15
+ # Tokenize the input
16
+ inputs = tokenizer(user_input, return_tensors="pt")
17
+
18
+ # Get model predictions
19
+ with torch.no_grad():
20
+ outputs = model(**inputs)
21
+
22
+ # Process the predictions (this will depend on your specific model output)
23
+ tokens = tokenizer.convert_ids_to_tokens(inputs['input_ids'][0])
24
+ predictions = torch.argmax(outputs.logits, dim=2)
25
+
26
+ # Display extracted keywords
27
+ st.write("Extracted Keywords:")
28
+ for token, pred in zip(tokens, predictions[0]):
29
+ if pred == 1: # Assuming label '1' corresponds to a keyword
30
+ st.write(token)
31
+
32
+ # # Add a slider for interaction (example)
33
+ # x = st.slider('Select a value')
34
+ # st.write(f"{x} squared is {x * x}")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ streamlit