gskdsrikrishna commited on
Commit
b860183
·
verified ·
1 Parent(s): f6e2884

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+
5
+ # Load API key from environment variables (or manually set it)
6
+ api_key = os.getenv("RAPIDAPI_KEY")
7
+
8
+ # Streamlit UI
9
+ st.title("AI Logo Generator 🎨")
10
+ st.write("Generate a unique logo for your business using AI!")
11
+
12
+ # User Inputs
13
+ prompt = st.text_input("Enter a description for the logo:", "Make a logo for my gaming company BTZ")
14
+ style = st.selectbox("Select a Logo Style:", [28, 29, 30], index=0) # Add more styles if available
15
+ size = st.radio("Select Image Size:", ["1-1", "2-3", "3-4"], index=0)
16
+
17
+ def generate_logo(prompt, style, size):
18
+ api_url = "https://ai-logo-generator.p.rapidapi.com/aaaaaaaaaaaaaaaaaiimagegenerator/quick.php"
19
+ headers = {
20
+ "x-rapidapi-key": api_key,
21
+ "x-rapidapi-host": "ai-logo-generator.p.rapidapi.com",
22
+ "Content-Type": "application/json"
23
+ }
24
+ payload = {
25
+ "prompt": prompt,
26
+ "style_id": style,
27
+ "size": size
28
+ }
29
+
30
+ response = requests.post(api_url, json=payload, headers=headers)
31
+ return response.json()
32
+
33
+ # Generate button
34
+ if st.button("Generate Logo"):
35
+ with st.spinner("Generating logo... Please wait!"):
36
+ result = generate_logo(prompt, style, size)
37
+
38
+ # Extracting image URLs from the JSON response
39
+ image_data = result.get("final_result", [])
40
+
41
+ if image_data:
42
+ st.subheader("Generated Logo Designs")
43
+
44
+ for index, image in enumerate(image_data):
45
+ image_url = image.get("origin") # Extracting the logo link
46
+
47
+ if image_url:
48
+ st.image(image_url, caption=f"Logo Design {index+1}", use_container_width=True)
49
+
50
+ # Download button with a unique key
51
+ st.download_button(
52
+ label="Download Logo",
53
+ data=requests.get(image_url).content,
54
+ file_name=f"logo_design_{index+1}.webp",
55
+ mime="image/webp",
56
+ key=f"download_{index}" # Unique key to prevent duplicate errors
57
+ )
58
+ else:
59
+ st.error("Failed to generate logo. No image URL found.")
60
+ st.write("Response Data:", result) # Debugging: Show full response data