import os import pandas as pd import openai import streamlit as st from src.E_openAI_embeddings import calculate_openai_similarity, get_openai_embedding from src.E_openAI_model import get_ballanced_intents, create_prompt, get_most_similar_intent, get_similarity_scores # Streamlit App st.title("Intent Detection using GPT-4 and Sentence Transformers") # side radio button for temperature # 0.5, 0.7, 0.9 temperature = st.sidebar.radio("Select temperature", [0.5, 0.7, 0.9]) # File uploader uploaded_file = st.file_uploader("Upload a CSV file", type="csv") if uploaded_file is not None: data = pd.read_csv(uploaded_file) # if data exeed 10000 rows, we will filter for 10000 rows #filtered_data = get_ballanced_intents(data) #st.write(filtered_data[:5]) #st.write(f"Filtered data shape: {filtered_data.intent.unique()}") st.session_state['data'] = data # filtered_data # Store the uploaded file in session state st.write("CSV file successfully uploaded!") # Load the data from session state if 'data' in st.session_state: data = st.session_state['data'] # Extract utterances and intents utterances = data['utterance'].tolist() intents = data['intent'].tolist() user_text = st.text_input("Enter user text:") if st.button("Detect Intent"): if user_text: most_similar_intent, confidence = get_most_similar_intent(user_text, utterances, intents) st.write(f"Most similar intent: {most_similar_intent}") st.write(f"Confidence: {confidence}") if user_text: # Get embedding for the user input user_embedding = get_openai_embedding(user_text) # Search in FAISS index for top 5 most similar sentences top_similar_sentences = calculate_openai_similarity(user_embedding, data, top_n=5) # Display the results st.write(f"Top 5 similar sentences:") for i, (sentence, score) in enumerate(top_similar_sentences): st.write(f"{i+1}. Sentence: {sentence}") st.write(f"Similarity score: {score:.4f}") else: st.write("Please enter some text.") else: st.write("Please upload a CSV file.") # User input user_input = st.text_input("Enter a sentence:")