Hug0endob commited on
Commit
bf89690
·
verified ·
1 Parent(s): c1ab3dd

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +13 -5
streamlit_app.py CHANGED
@@ -135,20 +135,28 @@ def strip_prompt_echo(prompt: str, text: str) -> str:
135
 
136
 
137
  def generate_inline(video_path: str, prompt: str, model_id: str, timeout: int) -> str:
 
138
  with open(video_path, "rb") as f:
139
  b64 = base64.b64encode(f.read()).decode()
 
 
140
  video_part = {
141
  "inline_data": {"mime_type": "video/mp4", "data": b64}
142
  }
143
  contents = [prompt, video_part]
144
 
145
- client = genai.Client()
146
- resp = client.models.generate_content(
147
- model=model_id,
148
- contents=contents,
 
 
149
  generation_config={"max_output_tokens": 1024},
150
- timeout=timeout,
 
151
  )
 
 
152
  return getattr(resp, "text", str(resp))
153
 
154
 
 
135
 
136
 
137
  def generate_inline(video_path: str, prompt: str, model_id: str, timeout: int) -> str:
138
+ # 1️⃣ read video and encode as base64
139
  with open(video_path, "rb") as f:
140
  b64 = base64.b64encode(f.read()).decode()
141
+
142
+ # 2️⃣ build the “inline” part that the Gemini API expects
143
  video_part = {
144
  "inline_data": {"mime_type": "video/mp4", "data": b64}
145
  }
146
  contents = [prompt, video_part]
147
 
148
+ # 3️⃣ create a GenerativeModel object (no Client class any more)
149
+ model = genai.GenerativeModel(model_name=model_id)
150
+
151
+ # 4️⃣ call generate_content – the timeout is passed via the request options
152
+ resp = model.generate_content(
153
+ contents,
154
  generation_config={"max_output_tokens": 1024},
155
+ # `timeout` is a kw‑arg of the underlying HTTP request; the SDK forwards it
156
+ request_options={"timeout": timeout},
157
  )
158
+
159
+ # 5️⃣ the response object has a `.text` attribute (or `.parts` for multi‑part)
160
  return getattr(resp, "text", str(resp))
161
 
162