Spaces:
Sleeping
Sleeping
Update image_gen.py
Browse files- image_gen.py +1 -11
image_gen.py
CHANGED
|
@@ -31,7 +31,6 @@ import dataframe_image as dfi
|
|
| 31 |
import uuid
|
| 32 |
from PIL import ImageFont, ImageDraw, Image
|
| 33 |
import seaborn as sns
|
| 34 |
-
import google.generativeai as ggenai
|
| 35 |
|
| 36 |
|
| 37 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -42,16 +41,7 @@ headers = {"Authorization": f"Bearer {token}"}
|
|
| 42 |
|
| 43 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 44 |
|
| 45 |
-
def configure_gemini(api_key):
|
| 46 |
-
try:
|
| 47 |
-
ggenai.configure(api_key=api_key)
|
| 48 |
-
return genai.GenerativeModel('gemini-2.0-flash-thinking-exp')
|
| 49 |
-
except Exception as e:
|
| 50 |
-
logger.error(f"Error configuring Gemini: {str(e)}")
|
| 51 |
-
raise
|
| 52 |
|
| 53 |
-
# Initialize Gemini model for story generation
|
| 54 |
-
model_g = configure_gemini(GOOGLE_API_KEY)
|
| 55 |
|
| 56 |
def is_valid_png(file_path):
|
| 57 |
"""Check if the PNG file at `file_path` is valid."""
|
|
@@ -187,7 +177,7 @@ def generate_image(prompt_text, style, model="hf"):
|
|
| 187 |
headers_pexels = {
|
| 188 |
"Authorization": pexels_api_key
|
| 189 |
}
|
| 190 |
-
new_prompt =
|
| 191 |
pexel_prompt = str(new_prompt.text)
|
| 192 |
|
| 193 |
search_url = f"https://api.pexels.com/v1/search?query={pexel_prompt}&per_page=1"
|
|
|
|
| 31 |
import uuid
|
| 32 |
from PIL import ImageFont, ImageDraw, Image
|
| 33 |
import seaborn as sns
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 41 |
|
| 42 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def is_valid_png(file_path):
|
| 47 |
"""Check if the PNG file at `file_path` is valid."""
|
|
|
|
| 177 |
headers_pexels = {
|
| 178 |
"Authorization": pexels_api_key
|
| 179 |
}
|
| 180 |
+
new_prompt = client.models.generate_content(model="models/gemini-2.0-flash-lite", contents=f"Generate keywords or a phrase to search for an appropriate image on the pexels API based on this prompt: {prompt_text} return only the keywords and nothing else")
|
| 181 |
pexel_prompt = str(new_prompt.text)
|
| 182 |
|
| 183 |
search_url = f"https://api.pexels.com/v1/search?query={pexel_prompt}&per_page=1"
|