Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from gradio_client import Client
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
-
import streamlit as st
|
8 |
|
9 |
# Initialize the HuggingFace Inference Client with the specified model
|
10 |
client_mistral = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
|
@@ -41,16 +40,16 @@ def generate_improved_prompt(logo_request, temperature=0.9, max_new_tokens=512,
|
|
41 |
output += response.token.text
|
42 |
yield output
|
43 |
|
44 |
-
def generate_image(prompt
|
45 |
result = client_playground.predict(
|
46 |
prompt,
|
47 |
-
|
48 |
-
|
49 |
-
seed
|
50 |
-
width
|
51 |
-
height
|
52 |
-
|
53 |
-
|
54 |
api_name="/run"
|
55 |
)
|
56 |
|
@@ -75,7 +74,12 @@ css = """
|
|
75 |
}
|
76 |
"""
|
77 |
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
79 |
with gr.Row():
|
80 |
with gr.Column(scale=2):
|
81 |
gr.HTML("<h1>Settings</h1>")
|
@@ -83,17 +87,17 @@ with gr.Blocks(css=css) as gpt:
|
|
83 |
with gr.Column(scale=3):
|
84 |
gr.HTML("<h1><center>Logo Prompt Generator<h1><center>")
|
85 |
generate_button = gr.Button("Generate")
|
86 |
-
|
87 |
generate_button.click(
|
88 |
-
fn=
|
89 |
inputs=[logo_input],
|
90 |
-
outputs=
|
91 |
)
|
92 |
|
93 |
gr.Markdown("""
|
94 |
---
|
95 |
### Meta Information
|
96 |
-
**Project Title**:
|
97 |
|
98 |
**Github**: [https://github.com/pacnimo/gpt-prompt-generator](https://github.com/pacnimo/)
|
99 |
|
@@ -102,24 +106,4 @@ with gr.Blocks(css=css) as gpt:
|
|
102 |
**Footer**: © 2024 by [pacnimo](https://github.com/pacnimo/). All rights reserved.
|
103 |
""") # Meta, project description, and footer added here
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
st.title("Image Generation using API")
|
108 |
-
|
109 |
-
# Streamlit app input fields
|
110 |
-
prompt = st.text_input("Enter prompt:", "")
|
111 |
-
negative_prompt = st.text_input("Enter negative prompt:", "")
|
112 |
-
use_negative_prompt = st.checkbox("Use negative prompt", False)
|
113 |
-
seed = st.number_input("Seed (0-2147483647):", value=0, min_value=0, max_value=2147483647)
|
114 |
-
width = st.slider("Width:", 1024, 1536)
|
115 |
-
height = st.slider("Height:", 1024, 1536)
|
116 |
-
guidance_scale = st.slider("Guidance Scale:", 3.0, 20.0, 0.1)
|
117 |
-
randomize_seed = st.checkbox("Randomize seed", True)
|
118 |
-
|
119 |
-
if st.button("Generate Image"):
|
120 |
-
with st.spinner("Generating image..."):
|
121 |
-
img = generate_image(prompt, negative_prompt, use_negative_prompt, seed, width, height, guidance_scale, randomize_seed)
|
122 |
-
if img:
|
123 |
-
st.image(img, caption="Generated Image")
|
124 |
-
else:
|
125 |
-
st.error("The content retrieved is not an image.")
|
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
from io import BytesIO
|
|
|
7 |
|
8 |
# Initialize the HuggingFace Inference Client with the specified model
|
9 |
client_mistral = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
|
|
|
40 |
output += response.token.text
|
41 |
yield output
|
42 |
|
43 |
+
def generate_image(prompt):
|
44 |
result = client_playground.predict(
|
45 |
prompt,
|
46 |
+
"", # negative prompt
|
47 |
+
False, # use negative prompt
|
48 |
+
0, # seed
|
49 |
+
1024, # width
|
50 |
+
1024, # height
|
51 |
+
7.5, # guidance scale
|
52 |
+
True, # randomize seed
|
53 |
api_name="/run"
|
54 |
)
|
55 |
|
|
|
74 |
}
|
75 |
"""
|
76 |
|
77 |
+
def process_request(logo_request):
|
78 |
+
improved_prompt = next(generate_improved_prompt(logo_request))
|
79 |
+
image = generate_image(improved_prompt)
|
80 |
+
return image
|
81 |
+
|
82 |
+
with gr.Blocks(css=css) as app:
|
83 |
with gr.Row():
|
84 |
with gr.Column(scale=2):
|
85 |
gr.HTML("<h1>Settings</h1>")
|
|
|
87 |
with gr.Column(scale=3):
|
88 |
gr.HTML("<h1><center>Logo Prompt Generator<h1><center>")
|
89 |
generate_button = gr.Button("Generate")
|
90 |
+
output_image = gr.Image(label="Generated Image")
|
91 |
generate_button.click(
|
92 |
+
fn=process_request,
|
93 |
inputs=[logo_input],
|
94 |
+
outputs=output_image
|
95 |
)
|
96 |
|
97 |
gr.Markdown("""
|
98 |
---
|
99 |
### Meta Information
|
100 |
+
**Project Title**: Logo Prompt Generator
|
101 |
|
102 |
**Github**: [https://github.com/pacnimo/gpt-prompt-generator](https://github.com/pacnimo/)
|
103 |
|
|
|
106 |
**Footer**: © 2024 by [pacnimo](https://github.com/pacnimo/). All rights reserved.
|
107 |
""") # Meta, project description, and footer added here
|
108 |
|
109 |
+
app.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|