Felguk commited on
Commit
b20e184
·
verified ·
1 Parent(s): 1feafeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -39
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import PyPDF2
4
  from PIL import Image
@@ -13,7 +13,6 @@ from torchvision.models.detection import fasterrcnn_resnet50_fpn
13
  from torchvision.transforms import functional as F
14
  import io
15
  import tempfile
16
- from moviepy.editor import VideoFileClip
17
 
18
  # Инициализация клиента для модели HuggingFaceH4/zephyr-7b-beta
19
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
@@ -89,30 +88,6 @@ def convert_image(image, target_format):
89
  img.save(tmp_file, format=target_format)
90
  return tmp_file.name
91
 
92
- # Функция для сжатия изображения
93
- def compress_image(image, quality):
94
- if image is None:
95
- return None
96
- img = Image.open(image.name)
97
-
98
- # Создаем временный файл
99
- with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp_file:
100
- img.save(tmp_file, format="JPEG", quality=quality)
101
- return tmp_file.name
102
-
103
- # Функция для сжатия видео
104
- def compress_video(video, quality):
105
- if video is None:
106
- return None
107
-
108
- # Загружаем видео
109
- clip = VideoFileClip(video.name)
110
-
111
- # Создаем временный файл
112
- with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file:
113
- clip.write_videofile(tmp_file.name, bitrate=f"{quality}k")
114
- return tmp_file.name
115
-
116
  # Функция для определения языка текста
117
  def detect_language(text):
118
  try:
@@ -247,19 +222,6 @@ with gr.Blocks() as demo:
247
  convert_button = gr.Button("Конвертировать")
248
  convert_button.click(fn=convert_image, inputs=[img_input, img_format], outputs=img_output)
249
 
250
- # Вкладка Minifile
251
- with gr.Tab("Minifile"):
252
- gr.Markdown("## Minifile: Сжатие видео и изображений")
253
- minifile_input = gr.File(label="Загрузите видео или изображение", file_types=["image", "video"])
254
- minifile_quality = gr.Slider(minimum=1, maximum=100, value=50, label="Качество (1-100)")
255
- minifile_output = gr.File(label="Результат сжатия")
256
- minifile_button = gr.Button("Сжать")
257
- minifile_button.click(
258
- fn=lambda file, quality: compress_image(file, quality) if file.name.split(".")[-1].lower() in ["jpg", "jpeg", "png", "bmp", "gif"] else compress_video(file, quality),
259
- inputs=[minifile_input, minifile_quality],
260
- outputs=minifile_output
261
- )
262
-
263
  # Интерфейс чата
264
  chat_interface = gr.ChatInterface(
265
  respond,
 
1
+ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import PyPDF2
4
  from PIL import Image
 
13
  from torchvision.transforms import functional as F
14
  import io
15
  import tempfile
 
16
 
17
  # Инициализация клиента для модели HuggingFaceH4/zephyr-7b-beta
18
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
88
  img.save(tmp_file, format=target_format)
89
  return tmp_file.name
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  # Функция для определения языка текста
92
  def detect_language(text):
93
  try:
 
222
  convert_button = gr.Button("Конвертировать")
223
  convert_button.click(fn=convert_image, inputs=[img_input, img_format], outputs=img_output)
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  # Интерфейс чата
226
  chat_interface = gr.ChatInterface(
227
  respond,