Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,3 @@
|
|
1 |
-
import os
|
2 |
-
import requests
|
3 |
import gradio as gr
|
4 |
-
from PIL import Image
|
5 |
-
from io import BytesIO
|
6 |
|
7 |
-
|
8 |
-
def generate_image(prompt):
|
9 |
-
API_URL = "https://api-inference.huggingface.co/models/prompthero/openjourney"
|
10 |
-
API_TOKEN = os.getenv("HF_READ_TOKEN") # Ensure the token is set in your environment
|
11 |
-
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
12 |
-
|
13 |
-
payload = {
|
14 |
-
"inputs": prompt
|
15 |
-
}
|
16 |
-
|
17 |
-
# Call the Hugging Face API to generate the image
|
18 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
19 |
-
|
20 |
-
# Check if the request was successful
|
21 |
-
if response.status_code != 200:
|
22 |
-
return f"Error: {response.status_code}, {response.text}"
|
23 |
-
|
24 |
-
# Convert the response content into a PIL image
|
25 |
-
image = Image.open(BytesIO(response.content))
|
26 |
-
|
27 |
-
return image # Return the image to Gradio
|
28 |
-
|
29 |
-
# Define the chatbot function to return the generated image
|
30 |
-
def chatbot(prompt):
|
31 |
-
image = generate_image(prompt)
|
32 |
-
return image
|
33 |
-
|
34 |
-
# Create the Gradio interface with the same UI/UX
|
35 |
-
interface = gr.Interface(
|
36 |
-
fn=chatbot,
|
37 |
-
inputs="text",
|
38 |
-
outputs="image",
|
39 |
-
title="prompthero/openjourney",
|
40 |
-
description="Enter a text prompt and get an AI-generated image."
|
41 |
-
)
|
42 |
-
|
43 |
-
# Launch the interface
|
44 |
-
interface.launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
gr.load("models/ZB-Tech/Text-to-Image").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|