pentarosarium commited on
Commit
cfd9f30
·
1 Parent(s): 0f1a490

LAUNCH APP WITH DISABLED API INFO

Browse files
Files changed (1) hide show
  1. app.py +113 -9
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import gradio as gr
 
 
2
  import spaces
3
  import pandas as pd
4
  import torch
@@ -20,6 +22,46 @@ import logging
20
  from typing import List, Set, Tuple
21
  import asyncio
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  def fuzzy_deduplicate(df, column, threshold=55):
24
  """Deduplicate rows based on fuzzy matching of text content"""
25
  seen_texts = []
@@ -903,21 +945,83 @@ def process_and_download(file_bytes, control=None):
903
 
904
  # Update the interface creation to pass the control object
905
  def create_interface():
906
- with gr.Blocks() as app:
907
- gr.Markdown("# Test Interface")
 
 
908
 
909
- file_input = gr.File(label="Upload File")
910
- btn = gr.Button("Process")
911
- output = gr.Textbox(label="Output")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
912
 
913
- btn.click(
914
- fn=lambda x: "File uploaded successfully!" if x else "No file",
 
915
  inputs=[file_input],
916
- outputs=[output]
 
 
 
 
 
 
 
917
  )
918
 
919
  return app
920
 
 
921
  if __name__ == "__main__":
922
  app = create_interface()
923
- app.launch()
 
 
 
 
 
 
1
  import gradio as gr
2
+ from gradio import blocks
3
+ from gradio_client import utils as client_utils
4
  import spaces
5
  import pandas as pd
6
  import torch
 
22
  from typing import List, Set, Tuple
23
  import asyncio
24
 
25
+ def patch_gradio():
26
+ # Patch the get_type function to handle boolean schemas
27
+ original_get_type = client_utils.get_type
28
+ def safe_get_type(schema):
29
+ if isinstance(schema, bool):
30
+ return "bool" # Return a string type for boolean values
31
+ try:
32
+ return original_get_type(schema)
33
+ except Exception:
34
+ return "Any" # Fallback type for any other issues
35
+
36
+ client_utils.get_type = safe_get_type
37
+
38
+ # Patch json_schema_to_python_type to handle exceptions
39
+ original_json_schema = client_utils.json_schema_to_python_type
40
+ def safe_json_schema(schema, *args, **kwargs):
41
+ try:
42
+ return original_json_schema(schema, *args, **kwargs)
43
+ except Exception:
44
+ return "Any" # Fallback for any schema parsing issues
45
+
46
+ client_utils.json_schema_to_python_type = safe_json_schema
47
+
48
+ # Disable API info generation entirely if it fails
49
+ original_get_api_info = blocks.Blocks.get_api_info
50
+ def safe_get_api_info(self):
51
+ try:
52
+ return original_get_api_info(self)
53
+ except Exception:
54
+ return {"components": [], "dependencies": []} # Empty API info
55
+
56
+ blocks.Blocks.get_api_info = safe_get_api_info
57
+
58
+ print("✅ Gradio patched successfully")
59
+
60
+
61
+ # Run the patch
62
+ patch_gradio()
63
+
64
+
65
  def fuzzy_deduplicate(df, column, threshold=55):
66
  """Deduplicate rows based on fuzzy matching of text content"""
67
  seen_texts = []
 
945
 
946
  # Update the interface creation to pass the control object
947
  def create_interface():
948
+ control = ProcessControl()
949
+
950
+ with gr.Blocks(analytics_enabled=False) as app:
951
+ gr.Markdown("# AI-анализ мониторинга новостей v.2.24a + extn")
952
 
953
+ with gr.Row():
954
+ file_input = gr.File(
955
+ label="Загрузите Excel файл",
956
+ file_types=[".xlsx"]
957
+ )
958
+
959
+ with gr.Row():
960
+ analyze_btn = gr.Button("▶️ Начать анализ", variant="primary")
961
+ stop_btn = gr.Button("⏹️ Остановить", variant="stop")
962
+
963
+ with gr.Row():
964
+ status_box = gr.Textbox(
965
+ label="Статус дедупликации",
966
+ interactive=False,
967
+ value=""
968
+ )
969
+
970
+ with gr.Row():
971
+ progress = gr.Textbox(
972
+ label="Статус обработки",
973
+ interactive=False,
974
+ value="Ожидание файла..."
975
+ )
976
+
977
+ with gr.Row():
978
+ stats = gr.DataFrame(
979
+ label="Результаты анализа",
980
+ interactive=False,
981
+ wrap=True # Use simple bool value
982
+ )
983
+
984
+ with gr.Row():
985
+ with gr.Column(scale=1):
986
+ sentiment_plot = gr.Plot(label="Распределение тональности")
987
+ with gr.Column(scale=1):
988
+ events_plot = gr.Plot(label="Распределение событий")
989
+
990
+ with gr.Row():
991
+ file_output = gr.File(
992
+ label="Скачать результаты",
993
+ visible=True,
994
+ interactive=True
995
+ )
996
+
997
+ def stop_processing():
998
+ control.request_stop()
999
+ return "Остановка обработки..."
1000
+
1001
+ stop_btn.click(fn=stop_processing, outputs=[progress])
1002
 
1003
+ # Main processing with control object passed
1004
+ analyze_btn.click(
1005
+ fn=lambda x: process_and_download(x, control),
1006
  inputs=[file_input],
1007
+ outputs=[
1008
+ stats,
1009
+ sentiment_plot,
1010
+ events_plot,
1011
+ file_output,
1012
+ progress,
1013
+ status_box
1014
+ ]
1015
  )
1016
 
1017
  return app
1018
 
1019
+ # === LAUNCH APP WITH DISABLED API INFO ===
1020
  if __name__ == "__main__":
1021
  app = create_interface()
1022
+ app.launch(
1023
+ server_name="0.0.0.0",
1024
+ server_port=7860,
1025
+ show_api=False, # Disable API info generation
1026
+ share=False # Don't attempt to create sharing links
1027
+ )