Geek7 commited on
Commit
5766b0d
·
verified ·
1 Parent(s): 760c15c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from flask import Flask, request, jsonify
2
  from flask_cors import CORS
3
  import os
4
  from huggingface_hub import InferenceClient
@@ -19,7 +19,16 @@ def generate_image(prompt, seed=1, model="prompthero/openjourney-v4"):
19
  try:
20
  # Generate the image using Hugging Face's inference API
21
  result_image = client.text_to_image(prompt=prompt, seed=seed, model=model)
22
- return result_image
 
 
 
 
 
 
 
 
 
23
  except Exception as e:
24
  print(f"Error generating image: {str(e)}")
25
  return None
@@ -47,7 +56,7 @@ gr.Interface(
47
  outputs="image",
48
  title="Image Generation with Hugging Face",
49
  description="Enter a prompt, seed, and model name to generate an image."
50
- ).launch() # Launch the Gradio interface
51
 
52
  # Add this block to make sure your app runs when called
53
  if __name__ == "__main__":
 
1
+ from flask import Flask, request
2
  from flask_cors import CORS
3
  import os
4
  from huggingface_hub import InferenceClient
 
19
  try:
20
  # Generate the image using Hugging Face's inference API
21
  result_image = client.text_to_image(prompt=prompt, seed=seed, model=model)
22
+
23
+ # Convert the result to a PIL Image
24
+ if isinstance(result_image, bytes):
25
+ # If the result is in bytes format
26
+ image = Image.open(BytesIO(result_image))
27
+ else:
28
+ # If the result is in another format, handle accordingly
29
+ raise ValueError("Received image in an unexpected format")
30
+
31
+ return image
32
  except Exception as e:
33
  print(f"Error generating image: {str(e)}")
34
  return None
 
56
  outputs="image",
57
  title="Image Generation with Hugging Face",
58
  description="Enter a prompt, seed, and model name to generate an image."
59
+ ).launch(share=True) # Launch the Gradio interface
60
 
61
  # Add this block to make sure your app runs when called
62
  if __name__ == "__main__":