Subbu1304 commited on
Commit
a3cbcf6
verified
1 Parent(s): 49652ab

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from transformers import pipeline
3
+
4
+ app = Flask(__name__)
5
+
6
+ # Load Stable Diffusion model (You can use OpenAI DALL路E API instead if preferred)
7
+ generator = pipeline('text-to-image', model='CompVis/stable-diffusion-v-1-4-original')
8
+
9
+ @app.route('/generate-image', methods=['POST'])
10
+ def generate_image():
11
+ description = request.json.get('description')
12
+ if not description:
13
+ return jsonify({'error': 'No description provided'}), 400
14
+
15
+ # Generate image from description
16
+ image = generator(description)
17
+
18
+ # Assuming image is returned as a URL or base64-encoded string
19
+ image_url = save_image(image) # Implement a function to save or serve the image
20
+
21
+ return jsonify({'image_url': image_url})
22
+
23
+ def save_image(image):
24
+ # Save image and return the URL or path for it
25
+ image_path = '/path/to/save/image.jpg'
26
+ image[0].save(image_path)
27
+ return image_path
28
+
29
+ if __name__ == '__main__':
30
+ app.run(debug=True)