Lokesh1024 commited on
Commit
2586b75
·
verified ·
1 Parent(s): 0dcb09f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ import openai
4
+ import streamlit as st
5
+
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ # Set up OpenAI API key
10
+ openai.api_key = os.getenv("API_KEY")
11
+
12
+ # Load context from file
13
+ with open("RamsayPersonality_V1.txt", "r") as file:
14
+ context = file.read()
15
+
16
+ # Streamlit app logic
17
+ st.title("RamsayGPT")
18
+ st.write("Welcome to RamsayGPT! Choose an option from the menu or type 'quit' to leave.")
19
+
20
+ menu = """Here are your options:
21
+ 1. Variations on a topic: I'll give you 3 alternative ways to tackle a problem and compare them. It's like showing you how to cook a steak three ways – you better not mess it up!
22
+ 2. Make a game for learning: We'll cook up an interactive game to teach you a concept step by step. Think of it as crafting a dessert with layers of information. Don't burn it!
23
+ 3. Explain a concept: I'll break down a topic into bite-sized pieces, perfect for your little beginner appetite. It's like explaining how to boil an egg to a clueless sous chef.
24
+ """
25
+
26
+ st.text(menu)
27
+
28
+ class RamsayGPT:
29
+ def __init__(self, api_key):
30
+ openai.api_key = api_key
31
+ self.context = context
32
+ self.chat_log = [{'role': 'assistant', 'content': self.context}]
33
+
34
+ def ramsay_response(self, user_message):
35
+ self.chat_log.append({"role": "user", "content": user_message})
36
+ try:
37
+ response = openai.ChatCompletion.create(
38
+ model="gpt-4",
39
+ messages=self.chat_log
40
+ )
41
+ assistant_response = response.choices[0].message.content
42
+ except Exception as e:
43
+ assistant_response = "Something went wrong, you donkey! Try again or type 'menu'."
44
+ return assistant_response.strip()
45
+
46
+ # Example usage
47
+ if st.button('Show Menu'):
48
+ st.write(menu)
49
+
50
+ user_input = st.text_input("You:")
51
+ if user_input:
52
+ ramsay = RamsayGPT(openai.api_key)
53
+ response = ramsay.ramsay_response(user_input)
54
+ st.write(response)