chansung commited on
Commit
d170f2b
·
verified ·
1 Parent(s): 7cf0fae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -39,22 +39,23 @@ async def echo(message, history, state, persona, use_generated_summaries):
39
  attached_file = find_attached_file(filename, state["attached_files"])
40
  if attached_file is None:
41
  path_gcp = await client.files.upload(path=path_local)
 
 
 
42
  state["attached_files"].append({
43
  "name": filename,
44
  "path_local": path_local,
45
  "gcp_entity": path_gcp,
46
- "path_gcp": path_gcp.name,
47
- "mime_type=": path_gcp.mime_type,
48
  "expiration_time": path_gcp.expiration_time,
49
  })
50
- attached_file = path_gcp
51
-
52
- user_message = [message['text']]
53
- if attached_file: user_message.append(attached_file)
54
 
55
- chat_history = state['messages']
56
- chat_history = chat_history + user_message
57
- state['messages'] = chat_history
 
58
 
59
  response_chunks = ""
60
  model_contents = ""
@@ -88,6 +89,10 @@ async def echo(message, history, state, persona, use_generated_summaries):
88
  ),
89
  gr.DownloadButton(visible=False)
90
  )
 
 
 
 
91
 
92
  # make summary
93
  response = await client.models.generate_content(
 
39
  attached_file = find_attached_file(filename, state["attached_files"])
40
  if attached_file is None:
41
  path_gcp = await client.files.upload(path=path_local)
42
+ path_wrap = types.Part.from_uri(
43
+ file_uri=path_gcp.uri, mime_type=path_gcp.mime_type
44
+ )
45
  state["attached_files"].append({
46
  "name": filename,
47
  "path_local": path_local,
48
  "gcp_entity": path_gcp,
49
+ "path_gcp": path_wrap,
50
+ "mime_type": path_gcp.mime_type,
51
  "expiration_time": path_gcp.expiration_time,
52
  })
53
+ attached_file = path_wrap
 
 
 
54
 
55
+ user_message_parts = [types.Part.from_text(text=message['text'])]
56
+ if attached_file: user_message_parts.append(attached_file)
57
+ user_message = [types.Content(role='user', parts=user_message_parts)]
58
+ state['messages'] = state['messages'] + user_message
59
 
60
  response_chunks = ""
61
  model_contents = ""
 
89
  ),
90
  gr.DownloadButton(visible=False)
91
  )
92
+
93
+ state['messages'] = state['messages'] + [
94
+ types.Content(role='model', parts=[types.Part.from_text(text=response_chunks)])
95
+ ]
96
 
97
  # make summary
98
  response = await client.models.generate_content(