Kvikontent
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,9 @@ import os
|
|
3 |
import requests
|
4 |
import io
|
5 |
from PIL import Image
|
|
|
6 |
|
|
|
7 |
hf_token = os.environ.get("API_TOKEN")
|
8 |
headers = {"Authorization": f"Bearer {hf_token}"}
|
9 |
API_URL_FACE = "https://api-inference.huggingface.co/models/prompthero/linkedin-diffusion"
|
@@ -15,44 +17,59 @@ API_URL_INKPUNK = "https://api-inference.huggingface.co/models/Envvi/Inkpunk-Dif
|
|
15 |
API_URL_DREAM = "https://api-inference.huggingface.co/models/Lykon/dreamshaper-xl-v2-turbo"
|
16 |
API_URL_COVER = "https://api-inference.huggingface.co/models/Norod78/sxl-laisha-magazine-cover-lora"
|
17 |
|
18 |
-
|
19 |
-
st.
|
20 |
-
model
|
21 |
-
|
22 |
-
|
23 |
-
)
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
})
|
53 |
-
image = Image.open(io.BytesIO(image_bytes))
|
54 |
-
return image
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import requests
|
4 |
import io
|
5 |
from PIL import Image
|
6 |
+
from freeGPT import Client
|
7 |
|
8 |
+
generative, chat = st.tab("Image Generation", "Chat")
|
9 |
hf_token = os.environ.get("API_TOKEN")
|
10 |
headers = {"Authorization": f"Bearer {hf_token}"}
|
11 |
API_URL_FACE = "https://api-inference.huggingface.co/models/prompthero/linkedin-diffusion"
|
|
|
17 |
API_URL_DREAM = "https://api-inference.huggingface.co/models/Lykon/dreamshaper-xl-v2-turbo"
|
18 |
API_URL_COVER = "https://api-inference.huggingface.co/models/Norod78/sxl-laisha-magazine-cover-lora"
|
19 |
|
20 |
+
with generative:
|
21 |
+
st.title("✨ Open Text2Image Models Leaderboard")
|
22 |
+
st.write("Choose one model to generate image and enter prompt")
|
23 |
+
model = st.selectbox(
|
24 |
+
'Model',
|
25 |
+
('Dall-e 3', 'Pixel', '3D Render', 'Realistic', 'Inkpunk', 'Dremscape', 'Magazine-cover', 'Faces')
|
26 |
+
)
|
27 |
+
prompt = st.text_area('Enter prompt')
|
28 |
+
button = st.button('Generate')
|
29 |
+
|
30 |
+
if model == 'Dall-e 3':
|
31 |
+
API_URL = API_URL_DALLE
|
32 |
+
elif model == 'Pixel':
|
33 |
+
API_URL = API_URL_PIX
|
34 |
+
elif model == '3D Render':
|
35 |
+
API_URL = API_URL_3D
|
36 |
+
elif model == 'Realistic':
|
37 |
+
API_URL = API_URL_REAL
|
38 |
+
elif model == 'Inkpunk':
|
39 |
+
API_URL = API_URL_INKPUNK
|
40 |
+
elif model == 'Dremscape':
|
41 |
+
API_URL = API_URL_DREAM
|
42 |
+
elif model == 'Magazine-cover':
|
43 |
+
API_URL = API_URL_COVER
|
44 |
+
elif model == 'Faces':
|
45 |
+
API_URL = API_URL_FACE
|
46 |
+
|
47 |
+
|
48 |
+
def query(payload):
|
49 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
50 |
+
return response.content
|
51 |
+
|
52 |
+
def generate_image(input_text):
|
53 |
+
image_bytes = query({
|
54 |
+
"inputs": input_text,
|
55 |
+
})
|
56 |
+
image = Image.open(io.BytesIO(image_bytes))
|
57 |
+
return image
|
58 |
|
59 |
+
if button:
|
60 |
+
generated_image = generate_image(prompt)
|
61 |
+
st.image(generated_image, caption='Generated Image')
|
|
|
|
|
|
|
62 |
|
63 |
+
with chat:
|
64 |
+
st.title("AI Chat")
|
65 |
+
prompt_gpt = st.chat_input("Ask something")
|
66 |
+
if prompt_gpt:
|
67 |
+
user_msg = st.chat_message("user")
|
68 |
+
user_msg.write(prompt_gpt)
|
69 |
+
try:
|
70 |
+
resp = Client.create_completion("gpt", prompt)
|
71 |
+
message_out = st.chat_message("assistant")
|
72 |
+
message_out.write(resp)
|
73 |
+
except Exception as e:
|
74 |
+
message_out = st.chat_message("assistant")
|
75 |
+
message_out.write(e)
|