chansung commited on
Commit
0be7331
·
verified ·
1 Parent(s): ea65fac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -14
app.py CHANGED
@@ -30,6 +30,7 @@ def find_attached_file(filename, attached_files):
30
  async def echo(message, history, state, persona, use_generated_summaries):
31
  attached_file = None
32
  system_instruction = Template(prompt_tmpl['summarization']['system_prompt']).safe_substitute(persona=persona)
 
33
  use_generated_summaries = True if use_generated_summaries == "Yes" else False
34
 
35
  if message['files']:
@@ -51,28 +52,52 @@ async def echo(message, history, state, persona, use_generated_summaries):
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 = ""
62
  if use_generated_summaries:
63
  if "summary_history" in state and len(state["summary_history"]):
64
- model_contents += state["summary_history"][-1]
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  else:
 
 
 
 
66
  model_contents = state['messages']
 
 
 
 
 
 
 
67
  else:
 
 
 
 
68
  model_contents = state['messages']
69
- model_content_stream = await client.models.generate_content_stream(
70
- model=args.model,
71
- contents=model_contents,
72
- config=types.GenerateContentConfig(
73
- system_instruction=system_instruction, seed=args.seed
74
- ),
75
- )
 
76
  async for chunk in model_content_stream:
77
  response_chunks += chunk.text
78
  # when model generates too fast, Gradio does not respond that in real-time.
 
30
  async def echo(message, history, state, persona, use_generated_summaries):
31
  attached_file = None
32
  system_instruction = Template(prompt_tmpl['summarization']['system_prompt']).safe_substitute(persona=persona)
33
+ system_instruction_cutoff = Template(prompt_tmpl['summarization']['system_prompt_cutoff'])
34
  use_generated_summaries = True if use_generated_summaries == "Yes" else False
35
 
36
  if message['files']:
 
52
  "expiration_time": path_gcp.expiration_time,
53
  })
54
  attached_file = path_wrap
55
+
 
 
 
 
 
56
  response_chunks = ""
57
  model_contents = ""
58
  if use_generated_summaries:
59
  if "summary_history" in state and len(state["summary_history"]):
60
+ user_message_parts = [
61
+ types.Part.from_text(text=f"""Summary\n:{state["summary_history"][-1]}\n-------"""),
62
+ types.Part.from_text(text=message['text'])
63
+ ]
64
+ if attached_file: user_message_parts.append(attached_file)
65
+ model_contents = [types.Content(role='user', parts=user_message_parts)]
66
+
67
+ model_content_stream = await client.models.generate_content_stream(
68
+ model=args.model,
69
+ contents=model_contents,
70
+ config=types.GenerateContentConfig(
71
+ system_instruction=system_instruction_cutoff, seed=args.seed
72
+ ),
73
+ )
74
  else:
75
+ user_message_parts = [types.Part.from_text(text=message['text'])]
76
+ if attached_file: user_message_parts.append(attached_file)
77
+ user_message = [types.Content(role='user', parts=user_message_parts)]
78
+
79
  model_contents = state['messages']
80
+ state['messages'] = model_contents + user_message
81
+
82
+ model_content_stream = await client.models.generate_content_stream(
83
+ model=args.model,
84
+ contents=model_contents,
85
+ config=types.GenerateContentConfig(seed=args.seed),
86
+ )
87
  else:
88
+ user_message_parts = [types.Part.from_text(text=message['text'])]
89
+ if attached_file: user_message_parts.append(attached_file)
90
+ user_message = [types.Content(role='user', parts=user_message_parts)]
91
+
92
  model_contents = state['messages']
93
+ state['messages'] = model_contents + user_message
94
+
95
+ model_content_stream = await client.models.generate_content_stream(
96
+ model=args.model,
97
+ contents=model_contents,
98
+ config=types.GenerateContentConfig(seed=args.seed),
99
+ )
100
+
101
  async for chunk in model_content_stream:
102
  response_chunks += chunk.text
103
  # when model generates too fast, Gradio does not respond that in real-time.