jfforero commited on
Commit
ea44288
1 Parent(s): 52fea70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -64,21 +64,27 @@ api_key = os.getenv("DeepAI_api_key")
64
 
65
 
66
 
67
- def generate_image(api_key, text):
68
- url = "https://api.deepai.org/api/text2img"
69
- headers = {'api-key': api_key}
70
- response = requests.post(
71
- url,
72
- data={'text': text},
73
- headers=headers
74
- )
75
- response_data = response.json()
76
- if 'output_url' in response_data:
77
- image_url = response_data['output_url']
78
- image_response = requests.get(image_url)
79
- image = Image.open(BytesIO(image_response.content))
80
- return image
81
- else:
 
 
 
 
 
 
82
  return None
83
 
84
 
 
64
 
65
 
66
 
67
+
68
+
69
+
70
+ def generate_image(emotion_prediction, transcribed_text):
71
+ try:
72
+ url = "https://api.deepai.org/api/image-editor"
73
+ headers = {
74
+ 'api-key': api_key
75
+ }
76
+ files = {
77
+ 'image': open('path_to_your_image.jpg', 'rb'), # Replace 'path_to_your_image.jpg' with the actual path to your image file
78
+ 'text': emotion_prediction + " " + transcribed_text
79
+ }
80
+ response = requests.post(url, headers=headers, files=files)
81
+ response_data = response.json()
82
+ if 'output_url' in response_data:
83
+ return response_data['output_url']
84
+ else:
85
+ return None
86
+ except Exception as e:
87
+ print("Error generating image:", e)
88
  return None
89
 
90