Spaces:
Sleeping
Sleeping
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}") | |