JeCabrera commited on
Commit
cdc830d
verified
1 Parent(s): df22630

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -58,6 +58,7 @@ def user(text_prompt: str, chatbot: CHAT_HISTORY):
58
  def bot(
59
  files: Optional[List[str]],
60
  model_choice: str,
 
61
  chatbot: CHAT_HISTORY
62
  ):
63
  if not GOOGLE_API_KEY:
@@ -74,7 +75,14 @@ def bot(
74
 
75
  text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
76
  image_prompt = [preprocess_image(Image.open(file).convert('RGB')) for file in files] if files else []
77
- model = genai.GenerativeModel(model_choice)
 
 
 
 
 
 
 
78
  response = model.generate_content(text_prompt + image_prompt, stream=True, generation_config=generation_config)
79
 
80
  chatbot[-1][1] = ""
@@ -85,6 +93,12 @@ def bot(
85
  time.sleep(0.01)
86
  yield chatbot
87
 
 
 
 
 
 
 
88
  chatbot_component = gr.Chatbot(
89
  label='Gemini',
90
  bubble_full_width=False,
@@ -113,9 +127,11 @@ user_inputs = [
113
  bot_inputs = [
114
  upload_button_component,
115
  model_choice_component,
 
116
  chatbot_component
117
  ]
118
 
 
119
  with gr.Blocks() as demo:
120
  gr.HTML(TITLE)
121
  gr.HTML(SUBTITLE)
@@ -126,6 +142,7 @@ with gr.Blocks() as demo:
126
  upload_button_component.render()
127
  run_button_component.render()
128
  model_choice_component.render()
 
129
 
130
  run_button_component.click(
131
  fn=user,
@@ -152,4 +169,5 @@ with gr.Blocks() as demo:
152
  queue=False
153
  )
154
 
 
155
  demo.queue(max_size=99).launch(debug=False, show_error=True)
 
58
  def bot(
59
  files: Optional[List[str]],
60
  model_choice: str,
61
+ system_instruction: str, # A帽adido el par谩metro para la instrucci贸n del sistema
62
  chatbot: CHAT_HISTORY
63
  ):
64
  if not GOOGLE_API_KEY:
 
75
 
76
  text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
77
  image_prompt = [preprocess_image(Image.open(file).convert('RGB')) for file in files] if files else []
78
+
79
+ # Crear el modelo con la instrucci贸n del sistema
80
+ model = genai.GenerativeModel(
81
+ model_name=model_choice,
82
+ generation_config=generation_config,
83
+ system_instruction=system_instruction # Se pasa la instrucci贸n del sistema
84
+ )
85
+
86
  response = model.generate_content(text_prompt + image_prompt, stream=True, generation_config=generation_config)
87
 
88
  chatbot[-1][1] = ""
 
93
  time.sleep(0.01)
94
  yield chatbot
95
 
96
+ # Componente para ingresar la instrucci贸n del sistema
97
+ system_instruction_component = gr.Textbox(
98
+ placeholder="Enter system instruction...", show_label=True, scale=8
99
+ )
100
+
101
+ # Definir los componentes de entrada y salida
102
  chatbot_component = gr.Chatbot(
103
  label='Gemini',
104
  bubble_full_width=False,
 
127
  bot_inputs = [
128
  upload_button_component,
129
  model_choice_component,
130
+ system_instruction_component, # A帽adido el campo de instrucci贸n del sistema
131
  chatbot_component
132
  ]
133
 
134
+ # Definir la interfaz de usuario
135
  with gr.Blocks() as demo:
136
  gr.HTML(TITLE)
137
  gr.HTML(SUBTITLE)
 
142
  upload_button_component.render()
143
  run_button_component.render()
144
  model_choice_component.render()
145
+ system_instruction_component.render() # Mostrar el campo de la instrucci贸n del sistema
146
 
147
  run_button_component.click(
148
  fn=user,
 
169
  queue=False
170
  )
171
 
172
+ # Lanzar la aplicaci贸n
173
  demo.queue(max_size=99).launch(debug=False, show_error=True)