wifix199 commited on
Commit
2cc7460
·
verified ·
1 Parent(s): 008a766

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -1
app.py CHANGED
@@ -1,8 +1,40 @@
1
  import gradio as gr
 
 
 
2
 
 
 
 
 
 
3
 
 
 
 
4
 
 
5
 
 
 
 
6
 
 
 
 
 
 
7
 
8
- gr.load("models/KingNish/flux-me",alias="our").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import requests
3
+ import os
4
+ import json
5
 
6
+ # Define the function that queries the Hugging Face API
7
+ def generate_image_from_model(prompt):
8
+ API_URL = "https://api-inference.huggingface.co/models/prompthero/openjourney"
9
+ API_TOKEN = os.getenv("HF_READ_TOKEN")
10
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
11
 
12
+ payload = {
13
+ "inputs": prompt,
14
+ }
15
 
16
+ response = requests.post(API_URL, headers=headers, json=payload)
17
 
18
+ # Handle errors
19
+ if response.status_code != 200:
20
+ return f"Error: {response.status_code}, {response.text}"
21
 
22
+ # Assuming the response is an image, save it temporarily and return the path
23
+ image_data = response.content
24
+ image_path = "generated_image.png"
25
+ with open(image_path, "wb") as img_file:
26
+ img_file.write(image_data)
27
 
28
+ return image_path # Return the path to the image
29
+
30
+ # Create the Gradio interface
31
+ interface = gr.Interface(
32
+ fn=generate_image_from_model,
33
+ inputs="text",
34
+ outputs="image",
35
+ title="OpenJourney Text-to-Image",
36
+ description="Enter a prompt to generate an image using OpenJourney model."
37
+ )
38
+
39
+ # Launch the interface
40
+ interface.launch()