File size: 2,564 Bytes
8ebeb01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import streamlit as st
from transformers import pipeline
import os
import PyPDF2

# Sidebar components
st.sidebar.title("TherapyGPT Settings")

# Model selection dropdown
model_option = st.sidebar.selectbox(
    "Choose AI Model:",
    ("GPT-4o", "distilgpt2", "gpt-neo")
)

# Document upload
uploaded_file = st.sidebar.file_uploader(
    "Upload Document", type=["txt", "pdf"])

# Workspace/session management
workspace_name = st.sidebar.text_input("Workspace Name", value="Default")
if st.sidebar.button("Create Workspace"):
    st.session_state.workspace = workspace_name
    st.session_state.chat_history = []  # Reset chat history


# Main chat area
st.title("TherapyGPT Chat")

# Display chat history if it exists
if 'chat_history' not in st.session_state:
    st.session_state.chat_history = []

for message in st.session_state.chat_history:
    st.write(f"{message['role']}: {message['content']}")

# User input
user_input = st.text_input("You:", "")
if st.button("Send"):
    if user_input:
        # Placeholder for model interaction (we'll integrate this next)
        st.session_state.chat_history.append(
            {"role": "User", "content": user_input})
        response = "I'm here to help."  # Temporary placeholder
        st.session_state.chat_history.append(
            {"role": "TherapyGPT", "content": response})


# Load the model based on selection

@st.cache_resource
def load_model(model_name):
    return pipeline("text-generation", model=model_name)


# Model selection logic
if model_option == "GPT-4o":
    # Replace with appropriate model
    model = load_model("ruslandev/llama-3-8b-gpt-4o-ru1.0-gguf")
elif model_option == "distilgpt2":
    pipe = pipeline("text-generation", model="distilbert/distilgpt2")
else:
    # Example HuggingFace model
    pipe = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")


def read_file(file):
    if file.name.endswith('.txt'):
        return file.read().decode('utf-8')
    elif file.name.endswith('.pdf'):
        pdf_reader = PyPDF2.PdfReader(file)
        return '\n'.join([page.extract_text() for page in pdf_reader.pages])


if uploaded_file:
    file_content = read_file(uploaded_file)
    st.sidebar.text_area("File Content", file_content, height=200)


if 'workspaces' not in st.session_state:
    st.session_state.workspaces = {}

# Load or create the workspace
if workspace_name not in st.session_state.workspaces:
    st.session_state.workspaces[workspace_name] = []

# Use the chat history for this workspace
chat_history = st.session_state.workspaces[workspace_name]