Spaces:
Sleeping
Sleeping
Commit
·
78338d6
1
Parent(s):
c5da5bd
Update app.py
Browse files
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 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
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.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|