aichina commited on
Commit
6aecf50
·
verified ·
1 Parent(s): 4a25b39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -19,23 +19,21 @@ def generate(text, file_name, second_file_name, api_key, model="gemini-2.0-flash
19
  # Initialize client using provided api_key (or fallback to env variable)
20
  client = genai.Client(api_key=(api_key.strip() if api_key and api_key.strip() != ""
21
  else os.environ.get("GEMINI_API_KEY")))
22
-
23
- files = [ client.files.upload(file=file_name) ]
24
- parts=[
25
- types.Part.from_uri(
26
- file_uri=files[0].uri,
27
- mime_type=files[0].mime_type,
28
- ),
29
-
30
 
31
- ]
32
  if second_file_name:
33
  second_file = client.files.upload(file=second_file_name)
34
  parts.append(types.Part.from_uri(
35
  file_uri=second_file.uri,
36
  mime_type=second_file.mime_type,
37
  ))
38
-
39
  parts.append(types.Part.from_text(text=text))
40
  print('parts',parts)
41
  contents = [
@@ -86,11 +84,12 @@ def process_image_and_prompt(composite_pil, second_composite_pil, prompt, gemini
86
  # Save the composite image to a temporary file.
87
  # Get the file extension of the composite image
88
  # Get the format/extension from PIL image object
89
-
90
- with tempfile.NamedTemporaryFile(suffix=f".png", delete=False) as tmp:
91
- composite_path = tmp.name
92
- print('composite_path',composite_path)
93
- composite_pil.save(composite_path)
 
94
 
95
  second_file_name = None
96
  if second_composite_pil:
 
19
  # Initialize client using provided api_key (or fallback to env variable)
20
  client = genai.Client(api_key=(api_key.strip() if api_key and api_key.strip() != ""
21
  else os.environ.get("GEMINI_API_KEY")))
22
+ parts = []
23
+ if file_name:
24
+ files = [ client.files.upload(file=file_name) ]
25
+ parts.append(types.Part.from_uri(
26
+ file_uri=files[0].uri,
27
+ mime_type=files[0].mime_type,
28
+ ))
 
29
 
 
30
  if second_file_name:
31
  second_file = client.files.upload(file=second_file_name)
32
  parts.append(types.Part.from_uri(
33
  file_uri=second_file.uri,
34
  mime_type=second_file.mime_type,
35
  ))
36
+
37
  parts.append(types.Part.from_text(text=text))
38
  print('parts',parts)
39
  contents = [
 
84
  # Save the composite image to a temporary file.
85
  # Get the file extension of the composite image
86
  # Get the format/extension from PIL image object
87
+ composite_path = None
88
+ if composite_pil:
89
+ with tempfile.NamedTemporaryFile(suffix=f".png", delete=False) as tmp:
90
+ composite_path = tmp.name
91
+ print('composite_path',composite_path)
92
+ composite_pil.save(composite_path)
93
 
94
  second_file_name = None
95
  if second_composite_pil: