CoolFace
Apppublic

awacke1/GenerativeAI-ChatInStreamlitWithTCPIP

sourceHugging Facemitupdated 4y agoView on Hugging Face
1likes
app.py47 linesDownload Raw Back to root
1import streamlit as st 2import pandas as pd3import socket 4 5# Create a socket6s = socket.socket()7 8# Sidebar9st.sidebar.title('Chat Options')10 11user_list = st.sidebar.selectbox('User List', ['User 1', 'User 2', 'User 3', 'User 4'])12 13# Main chat window 14st.title('TCP/IP Chat Session')15 16# Main program17if st.sidebar.button('Add Users'):18    # Get user list19    user_list = st.sidebar.selectbox('User List', ['User 1', 'User 2', 'User 3', 'User 4'])20 21# Create a dataframe to store chat messages22data = {'user': [], 'message': []}23df = pd.DataFrame(data)24 25# Connect to the server26host = '127.0.0.1'27port = 333428s.connect((host, port))29 30# Start the chat session31while True:32    # Read the messages from the server33    data = s.recv(1024)34    # Print the messages35    st.write(data)36    # Get user input37    message = st.text_input("Message: ")38    # Append user input to dataframe39    df = df.append({'user': user_list, 'message': message}, ignore_index=True)40    # Send the message to the server41    s.send(message.encode())42 43# Close the connection44s.close()45 46# Show the dataframe47st.dataframe(df)