Kvikontent commited on
Commit
93a8e41
·
verified ·
1 Parent(s): 10e46fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -39
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
- st.title("✨ Open Text2Image Models Leaderboard")
19
- st.write("Choose one model to generate image and enter prompt")
20
- model = st.selectbox(
21
- 'Model',
22
- ('Dall-e 3', 'Pixel', '3D Render', 'Realistic', 'Inkpunk', 'Dremscape', 'Magazine-cover', 'Faces')
23
- )
24
- prompt = st.text_area('Enter prompt')
25
- button = st.button('Generate')
26
-
27
- if model == 'Dall-e 3':
28
- API_URL = API_URL_DALLE
29
- elif model == 'Pixel':
30
- API_URL = API_URL_PIX
31
- elif model == '3D Render':
32
- API_URL = API_URL_3D
33
- elif model == 'Realistic':
34
- API_URL = API_URL_REAL
35
- elif model == 'Inkpunk':
36
- API_URL = API_URL_INKPUNK
37
- elif model == 'Dremscape':
38
- API_URL = API_URL_DREAM
39
- elif model == 'Magazine-cover':
40
- API_URL = API_URL_COVER
41
- elif model == 'Faces':
42
- API_URL = API_URL_FACE
43
-
44
-
45
- def query(payload):
46
- response = requests.post(API_URL, headers=headers, json=payload)
47
- return response.content
 
 
 
 
 
 
 
 
48
 
49
- def generate_image(input_text):
50
- image_bytes = query({
51
- "inputs": input_text,
52
- })
53
- image = Image.open(io.BytesIO(image_bytes))
54
- return image
55
 
56
- if button:
57
- generated_image = generate_image(prompt)
58
- st.image(generated_image, caption='Generated Image')
 
 
 
 
 
 
 
 
 
 
 
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)