Kvikontent commited on
Commit
78338d6
·
1 Parent(s): c5da5bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -45
app.py CHANGED
@@ -1,48 +1,19 @@
1
  import streamlit as st
2
  from freeGPT import Client
3
- from PIL import Image
4
- from io import BytesIO
5
 
6
- # Initialize the client with your API key
7
- client = Client()
8
-
9
- st.title("ChatBot")
10
- st.write("Welcome to our ChatBot! Ask me anything.")
11
-
12
- # Create a text area for user input
13
- user_input = st.text_area("Enter your message here: ", height=100)
14
-
15
- # Create a dropdown menu to select the mode
16
- mode_dropdown = st.selectbox("Select Mode", ["Text", "Image"], index=0)
17
-
18
- # Create a submit button
19
- submit_button = st.button("Submit")
20
-
21
- # Define a function to handle form submission
22
- def handle_form():
23
- global user_input
24
- if user_input != "":
25
- # Check the selected mode
26
- if mode_dropdown == "Text":
27
- # Generate response using the freeGPT model
28
- response = client.create_completion("gpt3", user_input)
29
-
30
- # Print the response
31
- st.write(response)
32
- elif mode_dropdown == "Image":
33
- # Generate image using the freeGPT model
34
- img_bytes = client.create_image("prodia", user_input)
35
-
36
- # Convert bytes to image object
37
- img = Image.open(BytesIO(img_bytes))
38
-
39
- # Show the image
40
- st.image(img, width=None, height=None)
41
- else:
42
- st.write("Please enter a valid message.")
43
-
44
- # Set up event handler for submit button click
45
- submit_button.onclick(handle_form)
46
-
47
- # Display the form
48
- st.form(user_input, mode_dropdown, submit_button)
 
1
  import streamlit as st
2
  from freeGPT import Client
 
 
3
 
4
+ @st.cache_data
5
+ def get_response(prompt):
6
+ try:
7
+ return Client.create_completion("gpt3", prompt).strip()
8
+ except Exception as e:
9
+ return f"Error: {e}"
10
+
11
+ st.title("KviGPT")
12
+ user_input = st.text_input("You: ", "")
13
+ generate_btn = st.button("Generate Response")
14
+
15
+ if generate_btn:
16
+ response = get_response(user_input)
17
+ st.markdown(response)
18
+ else:
19
+ st.write("Please provide a prompt to generate a response.")