MFawad commited on
Commit
8684aa6
β€’
1 Parent(s): 96031c2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -0
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import cohere
4
+
5
+ # Initialize Cohere Client
6
+ co = cohere.Client('mBS7SXo0I577gd5g5lScX3rw1YKupJHQq866YvS6') # Replace with your Cohere API key
7
+
8
+ # Function to generate text using Cohere API
9
+ # Function to generate text using Cohere API
10
+ def generate_text(prompt, temperature):
11
+ response = co.generate(
12
+ model='7f4b5dda-dcf2-40ca-9d4c-afdcaf435480-ft', # Replace with your Cohere model ID
13
+ prompt=prompt,
14
+ max_tokens= 2000,
15
+ temperature=temperature,
16
+ stop_sequences=['\n\n'],
17
+ )
18
+ return response
19
+
20
+ # Function to save chat history
21
+ def save_chat_history(chat_history):
22
+ with open("chat_history.pkl", "wb") as file:
23
+ pickle.dump(chat_history, file)
24
+
25
+ # Function to load chat history
26
+ def load_chat_history():
27
+ try:
28
+ with open("chat_history.pkl", "rb") as file:
29
+ return pickle.load(file)
30
+ except FileNotFoundError:
31
+ return []
32
+
33
+ # Streamlit app
34
+ def main():
35
+ st.markdown(
36
+ """
37
+ <style>
38
+ body {
39
+ background-image: url("https://www.creativefabrica.com/wp-content/uploads/2020/08/09/Set-of-hand-drawn-books-in-doodle-style-Graphics-4900608-1-580x385.jpg"); /* Replace "background.jpg" with your custom image */
40
+ background-size: cover;
41
+ }
42
+ </style>
43
+ """,
44
+ unsafe_allow_html=True
45
+ )
46
+ st.title("EdGuard πŸ“šπŸ€“")
47
+ st.write("Welcome to EdGuard your learning partner! πŸ˜‰πŸ˜Ž")
48
+ st.write("Use the example prompt or write your own. ✍🏼")
49
+
50
+ # Load chat history
51
+ chat_history = load_chat_history()
52
+
53
+ # Temperature slider
54
+ temperature = st.slider("Creativity", min_value=0.1, max_value=1.0, step=0.1, value=0.5)
55
+
56
+ # Example prompts
57
+ example_prompts = [
58
+ "A ball is thrown vertically upward with an initial velocity of 20 m/s. Assuming no air resistance, calculate the time it takes for the ball to reach its maximum height and the maximum height reached by the ball.",
59
+ "Calculate the number of moles of sodium chloride (NaCl) present in 250 grams of NaCl. (Molar Mass of NaCl = 58.44 g/mol)",
60
+ "What is the value of x: ((7x*2)/9)+8=10. ",
61
+ "A bakery sells cupcakes for $2.50 each. If Sarah buys 5 cupcakes and John buys 3 cupcakes, how much do they spend in total?"
62
+ ]
63
+
64
+ # Prompt selection
65
+ prompt_option = st.selectbox("Choose or enter a query:", ["Select an example query"] + example_prompts + ["Enter your own query"])
66
+
67
+ # Text area for custom prompt
68
+ if prompt_option == "Enter your own query":
69
+ prompt = st.text_area("Start Writing:")
70
+ elif prompt_option == "Select an example query":
71
+ prompt = ""
72
+ else:
73
+ prompt = prompt_option
74
+
75
+ # Generate text on button click
76
+ if st.button("Let's start learning!"):
77
+ with st.spinner("Generating..."):
78
+ generated_text = generate_text(prompt, temperature)
79
+ st.success("Yay!πŸŽ‰ I found something, let's look at it.")
80
+ st.write(generated_text)
81
+
82
+ # Save chat history
83
+ chat_history.append({"Question": prompt, "Response": generated_text})
84
+ save_chat_history(chat_history)
85
+
86
+ if __name__ == "__main__":
87
+ main()