Spaces:
Sleeping
Sleeping
Commit
·
c5da5bd
1
Parent(s):
ff6ac96
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
import freegpt
|
3 |
from freeGPT import Client
|
|
|
|
|
4 |
|
5 |
# Initialize the client with your API key
|
6 |
client = Client()
|
@@ -11,6 +12,9 @@ st.write("Welcome to our ChatBot! Ask me anything.")
|
|
11 |
# Create a text area for user input
|
12 |
user_input = st.text_area("Enter your message here: ", height=100)
|
13 |
|
|
|
|
|
|
|
14 |
# Create a submit button
|
15 |
submit_button = st.button("Submit")
|
16 |
|
@@ -18,11 +22,22 @@ submit_button = st.button("Submit")
|
|
18 |
def handle_form():
|
19 |
global user_input
|
20 |
if user_input != "":
|
21 |
-
#
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
else:
|
27 |
st.write("Please enter a valid message.")
|
28 |
|
@@ -30,4 +45,4 @@ def handle_form():
|
|
30 |
submit_button.onclick(handle_form)
|
31 |
|
32 |
# Display the form
|
33 |
-
st.form(user_input, submit_button)
|
|
|
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()
|
|
|
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 |
|
|
|
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 |
|
|
|
45 |
submit_button.onclick(handle_form)
|
46 |
|
47 |
# Display the form
|
48 |
+
st.form(user_input, mode_dropdown, submit_button)
|