VENKATESH2005 commited on
Commit
3dc3111
Β·
verified Β·
1 Parent(s): 6ffdca3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Set up page title and icon
5
+ st.set_page_config(page_title="🎭 Roleplay Chatbot", page_icon="πŸ€–")
6
+
7
+ # Load pre-trained chatbot model from Hugging Face
8
+ chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
9
+
10
+ st.title("🎭 Roleplay AI Chatbot")
11
+ st.write("Chat with an AI character!")
12
+
13
+ # Initialize chat history
14
+ if "messages" not in st.session_state:
15
+ st.session_state["messages"] = []
16
+
17
+ # Display chat history
18
+ for message in st.session_state["messages"]:
19
+ avatar = "πŸ§™β€β™‚οΈ" if message["role"] == "assistant" else "πŸ§‘β€πŸ’»"
20
+ with st.chat_message(message["role"], avatar=avatar):
21
+ st.markdown(message["content"])
22
+
23
+ # User input field
24
+ user_input = st.chat_input("Type your message...")
25
+
26
+ if user_input:
27
+ # Add user input to chat history
28
+ st.session_state["messages"].append({"role": "user", "content": user_input})
29
+
30
+ # Show typing animation
31
+ with st.chat_message("assistant", avatar="πŸ§™β€β™‚οΈ"):
32
+ with st.spinner("Typing..."):
33
+ response = chatbot(user_input, max_length=100, do_sample=True, temperature=0.7)
34
+ bot_reply = response[0]["generated_text"]
35
+ st.markdown(bot_reply)
36
+
37
+ # Save bot response to chat history
38
+ st.session_state["messages"].append({"role": "assistant", "content": bot_reply})