Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,71 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import transformers
|
3 |
|
4 |
-
# Load the pre-trained language model
|
5 |
-
model_name = "bert-base-uncased"
|
6 |
-
model = transformers.pipeline("text-classification", model=model_name)
|
7 |
|
8 |
-
# Streamlit App
|
9 |
-
def main():
|
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 |
-
# Function to classify the sentence using the pre-trained language model
|
35 |
-
@st.cache(allow_output_mutation=True)
|
36 |
-
def classify_sentence(query):
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
# import streamlit as st
|
2 |
+
# import transformers
|
3 |
|
4 |
+
# # Load the pre-trained language model
|
5 |
+
# model_name = "bert-base-uncased"
|
6 |
+
# model = transformers.pipeline("text-classification", model=model_name)
|
7 |
|
8 |
+
# # Streamlit App
|
9 |
+
# def main():
|
10 |
+
# st.title("Sentence Category Classifier")
|
11 |
|
12 |
+
# # Input search sentence
|
13 |
+
# search_query = st.text_input("Enter a sentence:")
|
14 |
|
15 |
+
# result = ""
|
16 |
|
17 |
+
# # Process the search sentence when the user clicks the Search button
|
18 |
+
# if st.button("Search"):
|
19 |
+
# if search_query:
|
20 |
+
# # Classify the sentence using the pre-trained model
|
21 |
+
# categories = classify_sentence(search_query)
|
22 |
|
23 |
+
# # Display the categories as output
|
24 |
+
# if categories:
|
25 |
+
# result = f"The sentence belongs to the following categories:\n\n"
|
26 |
+
# for category in categories:
|
27 |
+
# result += f"• {category}\n"
|
28 |
+
# else:
|
29 |
+
# result = "No categories found for the sentence."
|
30 |
|
31 |
+
# # Display the result
|
32 |
+
# st.text(result)
|
33 |
+
|
34 |
+
# # Function to classify the sentence using the pre-trained language model
|
35 |
+
# @st.cache(allow_output_mutation=True)
|
36 |
+
# def classify_sentence(query):
|
37 |
+
# # Classify the sentence using the pre-trained model
|
38 |
+
# categories = model(query)
|
39 |
|
40 |
+
# # Extract the category labels from the model's output
|
41 |
+
# category_labels = [category['label'] for category in categories]
|
42 |
|
43 |
+
# return category_labels
|
44 |
+
|
45 |
+
# if __name__ == "__main__":
|
46 |
+
# main()
|
47 |
+
|
48 |
+
import streamlit as st
|
49 |
+
|
50 |
+
# Function to categorize input sentences
|
51 |
+
def categorize_sentence(sentence):
|
52 |
+
# Replace this function with your own logic to categorize sentences
|
53 |
+
categories = ['Restaurants', 'Food', 'Travel', 'New York City']
|
54 |
+
return categories
|
55 |
+
|
56 |
+
# Configure Streamlit layout
|
57 |
+
st.set_page_config(page_title='Sentence Categorizer', layout='wide')
|
58 |
+
|
59 |
+
# Add title and description
|
60 |
+
st.title('Welcome to Sentence Categorizer')
|
61 |
+
st.write('Enter a sentence and discover relevant categories!')
|
62 |
+
|
63 |
+
# Create input box
|
64 |
+
sentence = st.text_input('Enter a sentence')
|
65 |
|
66 |
+
# Create button to trigger categorization
|
67 |
+
if st.button('Categorize'):
|
68 |
+
st.write('Categories:')
|
69 |
+
categories = categorize_sentence(sentence)
|
70 |
+
for category in categories:
|
71 |
+
st.success(category)
|