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