Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,44 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from gradio_client import Client
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import requests
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
def main():
|
| 8 |
+
st.title("Juggernaut-X-v10 Prediction")
|
| 9 |
+
|
| 10 |
+
# User input for the prompt
|
| 11 |
+
user_prompt = st.text_input("Enter your prompt:")
|
| 12 |
+
|
| 13 |
+
if st.button("Generate"):
|
| 14 |
+
with st.spinner('Generating...'):
|
| 15 |
+
# Call the Gradio API
|
| 16 |
+
client = Client("Walmart-the-bag/Juggernaut-X-v10")
|
| 17 |
+
result = client.predict(
|
| 18 |
+
prompt=user_prompt,
|
| 19 |
+
negative_prompt="easynegative, worst quality:1.4, bad composition:1.4, (bad anatomy:1.4, badly drawn hands:1.4, mutation, deformed, extra limb, missing limb, mutated limb, extra finger, missing finger), (deformed fingers:1.4, ugly fingers, ugly fingernails, deformed fingernails), watermarks, graphics, pixelation, blurry, artifacts, logo, (badly drawn face, badly drawn eyes, uneven eyes), imperfect proportions",
|
| 20 |
+
steps=50,
|
| 21 |
+
guidance_scale=7.5,
|
| 22 |
+
add_4k_masterpiece=False,
|
| 23 |
+
api_name="/predict"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Display the result image
|
| 27 |
+
image_path = result['image'] # Adjust according to the actual key in the result dictionary
|
| 28 |
+
if image_path:
|
| 29 |
+
image_url = f"http://localhost:8501{image_path}" # Adjust if needed
|
| 30 |
+
response = requests.get(image_url)
|
| 31 |
+
image = Image.open(BytesIO(response.content))
|
| 32 |
+
st.image(image, caption="Generated Image")
|
| 33 |
+
|
| 34 |
+
# Provide download button
|
| 35 |
+
image_bytes = BytesIO(response.content).getvalue()
|
| 36 |
+
st.download_button(
|
| 37 |
+
label="Download Image",
|
| 38 |
+
data=image_bytes,
|
| 39 |
+
file_name="generated_image.webp",
|
| 40 |
+
mime="image/webp"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
main()
|