Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,12 +11,24 @@ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
11 |
# Function to get response from Gemini model
|
12 |
def get_gemini_response(input_prompt, image_data, genre, length, language, mood):
|
13 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
14 |
-
|
|
|
15 |
full_prompt = f"""
|
16 |
-
You are a famous creative writer. Look at the image provided and
|
|
|
17 |
"""
|
18 |
response = model.generate_content([full_prompt, image_data[0]])
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
full_prompt = f"""
|
21 |
You are a creative writer. Create a {length} {genre} in {language}. The {genre} should be {mood}. The {genre} should be based on the following prompt:
|
22 |
|
@@ -26,12 +38,16 @@ def get_gemini_response(input_prompt, image_data, genre, length, language, mood)
|
|
26 |
"""
|
27 |
response = model.generate_content([full_prompt])
|
28 |
|
|
|
|
|
|
|
|
|
29 |
# Check if response is valid and return text
|
30 |
if response and response.parts:
|
31 |
return response.parts[0].text
|
32 |
else:
|
33 |
-
raise ValueError("Sorry,
|
34 |
-
|
35 |
# Function to setup uploaded image
|
36 |
def input_image_setup(uploaded_file):
|
37 |
if uploaded_file is not None:
|
|
|
11 |
# Function to get response from Gemini model
|
12 |
def get_gemini_response(input_prompt, image_data, genre, length, language, mood):
|
13 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
14 |
+
# If both image and text are provided
|
15 |
+
if image_data and input_prompt:
|
16 |
full_prompt = f"""
|
17 |
+
You are a famous creative writer. Look at the image provided and also consider the following prompt: "{input_prompt}".
|
18 |
+
Create a {length} {genre} in {language}. The {genre} should be {mood}, based on both the image and the prompt, and contain realistic and emotional elements.
|
19 |
"""
|
20 |
response = model.generate_content([full_prompt, image_data[0]])
|
21 |
+
|
22 |
+
# If only image is provided
|
23 |
+
elif image_data:
|
24 |
+
full_prompt = f"""
|
25 |
+
You are a famous creative writer. Look at the image provided and create a {length} {genre} in {language}.
|
26 |
+
The {genre} should be {mood}. The {genre} should be based on the image and contain realistic and emotional elements.
|
27 |
+
"""
|
28 |
+
response = model.generate_content([full_prompt, image_data[0]])
|
29 |
+
|
30 |
+
# If only text is provided
|
31 |
+
elif input_prompt:
|
32 |
full_prompt = f"""
|
33 |
You are a creative writer. Create a {length} {genre} in {language}. The {genre} should be {mood}. The {genre} should be based on the following prompt:
|
34 |
|
|
|
38 |
"""
|
39 |
response = model.generate_content([full_prompt])
|
40 |
|
41 |
+
# If neither image nor text is provided
|
42 |
+
else:
|
43 |
+
raise ValueError("Please provide either an image or a text prompt.")
|
44 |
+
|
45 |
# Check if response is valid and return text
|
46 |
if response and response.parts:
|
47 |
return response.parts[0].text
|
48 |
else:
|
49 |
+
raise ValueError("Sorry, please try a different combination of inputs.")
|
50 |
+
|
51 |
# Function to setup uploaded image
|
52 |
def input_image_setup(uploaded_file):
|
53 |
if uploaded_file is not None:
|