mesutt commited on
Commit
5b9b9ba
1 Parent(s): 3853329

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -5
app.py CHANGED
@@ -1,5 +1,46 @@
1
- import gradio as gr
2
- title = "Text to image with SDv1.5 in Gradio"
3
- description = "Type input area your prompt and wait till return an image about your prompt"
4
- text_to_image = gr.Interface.load("huggingface/runwayml/stable-diffusion-v1-5")
5
- gr.Interface(fn=text_to_image, inputs="text", outputs="image", title=title, description=description).launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+ from PIL import Image
4
+ import base64
5
+
6
+ def t2i(text):
7
+ prompt_url = f"https://aadarsh-text-to-image-mymvubi2mq-el.a.run.app/t2i/{text}"
8
+ img_url = requests.get(prompt_url).json()["url"]
9
+ response = requests.get(img_url)
10
+ if response.status_code:
11
+ fp = open('image.png', 'wb')
12
+ fp.write(response.content)
13
+ fp.close()
14
+
15
+ image = Image.open('image.png')
16
+ return image
17
+
18
+ # Read the image file and encode it as base64
19
+ with open("./1001epochs.png", "rb") as f:
20
+ image_data = f.read()
21
+ image_base64 = base64.b64encode(image_data).decode("utf-8")
22
+
23
+ allow_flagging = "never"
24
+
25
+ title = f"""
26
+ <h2 style="background-image: linear-gradient(to right, #3A5FCD, #87CEFA); -webkit-background-clip: text;
27
+ -webkit-text-fill-color: transparent; text-align: center;">
28
+ Text to Image Generator
29
+ </h2>
30
+ """
31
+
32
+ description = f"""
33
+ <div style="display: flex; align-items: center; justify-content: center; flex-direction: column;">
34
+ <p style="font-size: 18px; color: #4AAAFF; text-align: center;">
35
+ Turn words into captivating visuals effortlessly within minutes.
36
+ </p>
37
+ <div style="display: flex; align-items: center; margin-bottom: 0px;">
38
+ <img src='data:image/jpeg;base64,{image_base64}' width='50' height='30' style="margin-right: 5px;"/>
39
+ <p style="font-size: 14px; color: #555;">
40
+ Disclaimer: The purpose of this application is solely for demonstration. 1001epochs does not claim ownership for the results Contact: [email protected] for full solution.
41
+ </p>
42
+ </div>
43
+ </div>
44
+ """
45
+ iface = gr.Interface(fn=t2i, inputs="text", outputs=[gr.Image(label="Generated Image")], title=title, description=description).launch()
46
+ iface.launch(share=True)