Rooni commited on
Commit
6ac9ccb
·
1 Parent(s): 83eef3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -29
app.py CHANGED
@@ -13,12 +13,8 @@ def encode_image_to_base64(image):
13
  # Функция, которая будет вызываться при нажатии кнопки отправки
14
  def send_message(message, image=None):
15
  # Здесь будет логика отправки сообщения и получения ответа от бота
16
- # Для примера просто возвращаем полученное сообщение и изображение
17
- response = f"Вы сказали: {message}"
18
- if image:
19
- img_str = encode_image_to_base64(image)
20
- return response, f"data:image/jpeg;base64,{img_str}"
21
- return response, None
22
 
23
  css = """
24
  footer {visibility: hidden !important;}
@@ -30,26 +26,20 @@ footer {visibility: hidden !important;}
30
 
31
  # Создаем интерфейс
32
  with gr.Blocks(css=css) as demo:
33
- with gr.Row().style(equal_height=False):
34
- chat_history = gr.Markdown("Привет! Я Помогатор, готов помочь тебе с любыми вопросами!) 😊").style(
35
- container=True,
36
- scroll="auto",
37
- height="auto",
38
- max_height="400px"
39
- )
40
- with gr.Row().style(justify_content="center", padding="10px"):
41
- with gr.Column(scale=12):
42
- input_message = gr.Textbox(placeholder="Введите ваше сообщение здесь...", lines=2, interactive=True, max_lines=5)
43
- with gr.Column(scale=1, min_width="50px"):
44
- send_button = gr.Button("Отправить")
45
- with gr.Column(scale=1, min_width="50px"):
46
- attach_button = gr.File(label="", file_count="single", interactive=True)
47
- attach_button.style(icon="paperclip", hide_label=True)
48
- with gr.Column(scale=1, min_width="50px"):
49
- clear_button = gr.Button(label="")
50
- clear_button.style(icon="times", hide_label=True, visible=False)
51
 
52
- # Функция для отображения предварительного просмотра изображения
53
  def preview_image(file_info):
54
  if file_info is not None:
55
  clear_button.style(visible=True)
@@ -62,24 +52,20 @@ with gr.Blocks(css=css) as demo:
62
  attach_button.style(visible=True)
63
  return None
64
 
65
- # Функция для очистки загруженного изображения
66
  def clear_image():
67
  attach_button.reset()
68
  clear_button.style(visible=False)
69
  attach_button.style(visible=True)
70
  return None
71
 
72
- # Функция для обработки отправки сообщения
73
  def handle_send(message, image=None):
74
  response, img_str = send_message(message, image)
75
  new_message = f"**Вы:** {message}\n\n" if message else ""
76
- new_message += f"![uploaded image]({img_str})\n\n" if img_str else ""
77
  new_message += f"**Помогатор:** {response}\n\n"
78
  chat_history.update(new_message + chat_history.value)
79
  input_message.reset()
80
  clear_image()
81
 
82
- # Привязываем функции к кнопкам и полям ввода
83
  send_button.click(handle_send, inputs=[input_message, attach_button], outputs=[])
84
  attach_button.change(preview_image, inputs=[attach_button], outputs=[chat_history])
85
  clear_button.click(clear_image, inputs=[], outputs=[chat_history])
 
13
  # Функция, которая будет вызываться при нажатии кнопки отправки
14
  def send_message(message, image=None):
15
  # Здесь будет логика отправки сообщения и получения ответа от бота
16
+ response = "Это ответ бота на ваше сообщение."
17
+ return response, ""
 
 
 
 
18
 
19
  css = """
20
  footer {visibility: hidden !important;}
 
26
 
27
  # Создаем интерфейс
28
  with gr.Blocks(css=css) as demo:
29
+ chat_history = gr.Markdown("Привет! Я Помогатор, готов помочь тебе с любыми вопросами!) 😊").style(
30
+ container=True,
31
+ scroll="auto",
32
+ height="auto",
33
+ max_height="400px"
34
+ )
35
+ with gr.Row():
36
+ input_message = gr.Textbox(placeholder="Введите ваше сообщение здесь...", lines=2, interactive=True, max_lines=5)
37
+ send_button = gr.Button("Отправить")
38
+ attach_button = gr.File(label="", file_count="single", interactive=True)
39
+ attach_button.style(icon="paperclip", hide_label=True)
40
+ clear_button = gr.Button(label="")
41
+ clear_button.style(icon="times", hide_label=True, visible=False)
 
 
 
 
 
42
 
 
43
  def preview_image(file_info):
44
  if file_info is not None:
45
  clear_button.style(visible=True)
 
52
  attach_button.style(visible=True)
53
  return None
54
 
 
55
  def clear_image():
56
  attach_button.reset()
57
  clear_button.style(visible=False)
58
  attach_button.style(visible=True)
59
  return None
60
 
 
61
  def handle_send(message, image=None):
62
  response, img_str = send_message(message, image)
63
  new_message = f"**Вы:** {message}\n\n" if message else ""
 
64
  new_message += f"**Помогатор:** {response}\n\n"
65
  chat_history.update(new_message + chat_history.value)
66
  input_message.reset()
67
  clear_image()
68
 
 
69
  send_button.click(handle_send, inputs=[input_message, attach_button], outputs=[])
70
  attach_button.change(preview_image, inputs=[attach_button], outputs=[chat_history])
71
  clear_button.click(clear_image, inputs=[], outputs=[chat_history])