Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,43 @@ from gradio_client import Client
|
|
| 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")
|
| 10 |
-
# Initialize the Playground AI client
|
| 11 |
-
client_playground = Client(
|
| 12 |
|
| 13 |
def format_prompt(logo_request):
|
| 14 |
system_prompt = """
|
|
@@ -55,7 +87,7 @@ def generate_image(prompt, width=1024, height=1024, guidance_scale=7.5):
|
|
| 55 |
|
| 56 |
# Extract the image URL from the result
|
| 57 |
image_path = result[0][0]["image"]
|
| 58 |
-
image_url = "
|
| 59 |
|
| 60 |
# Fetch and display the result image
|
| 61 |
response = requests.get(image_url)
|
|
@@ -103,11 +135,11 @@ with gr.Blocks(css=css) as app:
|
|
| 103 |
### Meta Information
|
| 104 |
**Project Title**:Magical AI Logo Generator
|
| 105 |
|
| 106 |
-
**Github**: [https://github.com/pacnimo/
|
| 107 |
|
| 108 |
-
**Description**: Magical AI Logo Generator is Free and Easy to Use. Create a
|
| 109 |
|
| 110 |
**Footer**: © 2024 by [pacnimo](https://github.com/pacnimo/). All rights reserved.
|
| 111 |
""")
|
| 112 |
|
| 113 |
-
app.launch(debug=True)
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import requests
|
| 6 |
from io import BytesIO
|
| 7 |
+
import re
|
| 8 |
+
|
| 9 |
+
# Function to fetch the API endpoint from the URL using regular expressions
|
| 10 |
+
def fetch_api_endpoint(url):
|
| 11 |
+
try:
|
| 12 |
+
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
|
| 13 |
+
response = requests.get(url, headers=headers)
|
| 14 |
+
response.raise_for_status() # Raise exception for HTTP errors
|
| 15 |
+
|
| 16 |
+
# Use regular expressions to find the endpoint URL in the script content
|
| 17 |
+
endpoint_match = re.search(r'root":"(https://[^"]+)', response.text)
|
| 18 |
+
if endpoint_match:
|
| 19 |
+
endpoint_url = endpoint_match.group(1)
|
| 20 |
+
return endpoint_url
|
| 21 |
+
else:
|
| 22 |
+
return None
|
| 23 |
+
except requests.RequestException as e:
|
| 24 |
+
print("Error fetching URL:", e)
|
| 25 |
+
return None
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print("An unexpected error occurred:", e)
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
# Define the URL to fetch the API endpoint from
|
| 31 |
+
url = "https://playgroundai-playground-v2-5.hf.space/"
|
| 32 |
+
|
| 33 |
+
# Fetch the API endpoint
|
| 34 |
+
endpoint = fetch_api_endpoint(url)
|
| 35 |
+
|
| 36 |
+
if endpoint is None:
|
| 37 |
+
print("Failed to fetch the API endpoint.")
|
| 38 |
+
exit(1)
|
| 39 |
|
| 40 |
# Initialize the HuggingFace Inference Client with the specified model
|
| 41 |
client_mistral = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
|
| 42 |
+
# Initialize the Playground AI client with the fetched endpoint
|
| 43 |
+
client_playground = Client(endpoint)
|
| 44 |
|
| 45 |
def format_prompt(logo_request):
|
| 46 |
system_prompt = """
|
|
|
|
| 87 |
|
| 88 |
# Extract the image URL from the result
|
| 89 |
image_path = result[0][0]["image"]
|
| 90 |
+
image_url = endpoint + "/file=" + image_path
|
| 91 |
|
| 92 |
# Fetch and display the result image
|
| 93 |
response = requests.get(image_url)
|
|
|
|
| 135 |
### Meta Information
|
| 136 |
**Project Title**:Magical AI Logo Generator
|
| 137 |
|
| 138 |
+
**Github**: [https://github.com/pacnimo/](https://github.com/pacnimo/)
|
| 139 |
|
| 140 |
+
**Description**: Magical AI Logo Generator is Free and Easy to Use. Create a Website Logo with just 1 Click.
|
| 141 |
|
| 142 |
**Footer**: © 2024 by [pacnimo](https://github.com/pacnimo/). All rights reserved.
|
| 143 |
""")
|
| 144 |
|
| 145 |
+
app.launch(debug=True)
|