MarwanAshraf22 commited on
Commit
a8d8832
·
1 Parent(s): b75f00f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
4
+
5
+ # Load pre-trained model and tokenizer
6
+ model_name = "distilbert-base-uncased"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
+
10
+ # Create Streamlit app
11
+ st.title("Hugging Face Transformers + Streamlit Example")
12
+
13
+ # Define a function to use the model for prediction
14
+ @st.cache(allow_output_mutation=True)
15
+ def run_model(input_text):
16
+ inputs = tokenizer(input_text, return_tensors="pt")
17
+ outputs = model(**inputs)
18
+ predictions = torch.softmax(outputs.logits, dim=1)
19
+ return predictions
20
+
21
+ # Streamlit interface
22
+ user_input = st.text_input("Enter text:", "Type Here...")
23
+ if st.button("Predict"):
24
+ predictions = run_model(user_input)
25
+ st.write(f"Predictions: {predictions}")