mknolan commited on
Commit
a7fa119
·
verified ·
1 Parent(s): 8645fb5

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +63 -64
app.py CHANGED
@@ -1611,6 +1611,34 @@ def get_latest_log_content():
1611
  except Exception as e:
1612
  return f"Error reading log file: {str(e)}"
1613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1614
  # Main function
1615
  def main():
1616
  # Load the model
@@ -1638,50 +1666,42 @@ def main():
1638
  "Summarize what you see in this image in one paragraph."
1639
  ]
1640
 
1641
- # Simple function to read log file
1642
- def read_log_file():
1643
- try:
1644
- with open(log_file, 'r') as f:
1645
- return f.read()
1646
- except Exception as e:
1647
- return f"Error reading log file: {str(e)}"
1648
-
1649
- # Create tabs for different modes
1650
  with gr.Blocks(title="InternVL2.5 Image Analyzer", theme=gr.themes.Soft()) as demo:
1651
  gr.Markdown("# InternVL2.5 Image Analyzer")
1652
  gr.Markdown("Analyze images using the InternVL2.5 model. You can upload individual images or analyze all images in a folder.")
1653
 
1654
- # Add a simple logs view tab first
1655
- with gr.Tab("Debug Logs"):
1656
- gr.Markdown("## View Application Logs")
1657
-
1658
- with gr.Row():
1659
- with gr.Column(scale=3):
1660
- logs_output = gr.Textbox(
1661
- label="Application Logs",
1662
- value=read_log_file(),
1663
- lines=30,
1664
- max_lines=50
1665
- )
1666
- with gr.Column(scale=1):
1667
- refresh_logs_btn = gr.Button("Refresh Logs")
1668
- log_info = gr.Markdown(f"Log file: {log_file}")
1669
-
1670
- # Simple error stats
1671
- error_stats = gr.Markdown(f"Error count: {error_count}")
1672
-
1673
- refresh_logs_btn.click(
1674
- fn=read_log_file,
1675
- inputs=[],
1676
- outputs=[logs_output]
1677
- )
 
 
 
 
 
1678
 
1679
- # Add download button for log file
1680
- gr.File(label="Download Log File", value=log_file)
1681
-
1682
- # Main tabs for functionality
1683
- with gr.Tabs():
1684
- # Tab for single image analysis
1685
  with gr.Tab("Single Image Analysis"):
1686
  with gr.Row():
1687
  image_input = gr.Image(type="pil", label="Upload Image or PDF")
@@ -1712,7 +1732,7 @@ def main():
1712
  outputs=save_status_single
1713
  )
1714
 
1715
- # Tab for dual image analysis
1716
  with gr.Tab("Dual Image Analysis"):
1717
  with gr.Row():
1718
  image1_input = gr.Image(type="pil", label="Upload First Image")
@@ -1744,7 +1764,7 @@ def main():
1744
  outputs=save_status_dual
1745
  )
1746
 
1747
- # Tab for folder analysis
1748
  with gr.Tab("Folder Analysis"):
1749
  gr.Markdown("## Analyze all images and PDFs in a folder")
1750
  gr.Markdown("""
@@ -1874,7 +1894,7 @@ def main():
1874
  yield folder_status_msg, ""
1875
  except:
1876
  pass
1877
-
1878
  # Run analysis
1879
  folder_status_msg = "Processing images... (this may take several minutes)"
1880
  yield folder_status_msg, ""
@@ -1921,28 +1941,7 @@ def main():
1921
  outputs=[save_status_folder]
1922
  )
1923
 
1924
- # Add a new tab for logs
1925
- with gr.Tab("Debug Logs"):
1926
- gr.Markdown("## Debug Logs")
1927
- gr.Markdown("View the latest application logs to diagnose issues:")
1928
-
1929
- log_output = gr.Textbox(
1930
- value=get_latest_log_content(),
1931
- lines=20,
1932
- label="Latest Log Entries",
1933
- elem_id="log_output"
1934
- )
1935
-
1936
- refresh_btn = gr.Button("Refresh Logs")
1937
- refresh_btn.click(
1938
- fn=get_latest_log_content,
1939
- inputs=[],
1940
- outputs=[log_output]
1941
- )
1942
-
1943
- gr.Markdown("**Note**: Log files are also saved to the `saved_outputs` directory and can be accessed via the Files tab.")
1944
-
1945
- # New tab for saved output files
1946
  with gr.Tab("Saved Outputs"):
1947
  refresh_btn = gr.Button("Refresh File List")
1948
  file_list = gr.Markdown(value=list_output_files())
 
1611
  except Exception as e:
1612
  return f"Error reading log file: {str(e)}"
1613
 
1614
+ # Initialize GUI stats at the top level
1615
+ gui_stats = {
1616
+ 'errors': 0,
1617
+ 'warnings': 0,
1618
+ 'last_error': 'None',
1619
+ 'last_warning': 'None',
1620
+ 'last_error_time': '',
1621
+ 'last_warning_time': '',
1622
+ 'operations_completed': 0,
1623
+ 'start_time': datetime.datetime.now(),
1624
+ 'tensor_issues': 0
1625
+ }
1626
+
1627
+ # Function to read log file content
1628
+ def read_log_file():
1629
+ """Read and return the contents of the current log file."""
1630
+ try:
1631
+ if not os.path.exists(log_file):
1632
+ return "Log file not found. The application may have just started."
1633
+
1634
+ with open(log_file, 'r', encoding='utf-8') as f:
1635
+ content = f.read()
1636
+ if not content:
1637
+ return "Log file is empty. Waiting for events..."
1638
+ return content
1639
+ except Exception as e:
1640
+ return f"Error reading log file: {str(e)}"
1641
+
1642
  # Main function
1643
  def main():
1644
  # Load the model
 
1666
  "Summarize what you see in this image in one paragraph."
1667
  ]
1668
 
1669
+ # Create the main interface
 
 
 
 
 
 
 
 
1670
  with gr.Blocks(title="InternVL2.5 Image Analyzer", theme=gr.themes.Soft()) as demo:
1671
  gr.Markdown("# InternVL2.5 Image Analyzer")
1672
  gr.Markdown("Analyze images using the InternVL2.5 model. You can upload individual images or analyze all images in a folder.")
1673
 
1674
+ # Create all tabs at the same level
1675
+ with gr.Tabs() as tabs:
1676
+ # Debug Logs tab - placed first for visibility
1677
+ with gr.Tab("Debug Logs"):
1678
+ gr.Markdown("## Application Logs")
1679
+ gr.Markdown("View real-time application logs and debug information.")
1680
+
1681
+ with gr.Row():
1682
+ with gr.Column(scale=3):
1683
+ logs_output = gr.Textbox(
1684
+ label="Application Logs",
1685
+ value=read_log_file(),
1686
+ lines=30,
1687
+ max_lines=50,
1688
+ autoscroll=True
1689
+ )
1690
+ with gr.Column(scale=1):
1691
+ refresh_logs_btn = gr.Button("Refresh Logs")
1692
+ log_info = gr.Markdown(f"Current log file: {log_file}")
1693
+ error_stats = gr.Markdown(f"Error count: {gui_stats['errors']}")
1694
+
1695
+ refresh_logs_btn.click(
1696
+ fn=read_log_file,
1697
+ inputs=[],
1698
+ outputs=[logs_output]
1699
+ )
1700
+
1701
+ # Add download button for log file
1702
+ gr.File(label="Download Complete Log File", value=log_file)
1703
 
1704
+ # Single Image Analysis tab
 
 
 
 
 
1705
  with gr.Tab("Single Image Analysis"):
1706
  with gr.Row():
1707
  image_input = gr.Image(type="pil", label="Upload Image or PDF")
 
1732
  outputs=save_status_single
1733
  )
1734
 
1735
+ # Dual Image Analysis tab
1736
  with gr.Tab("Dual Image Analysis"):
1737
  with gr.Row():
1738
  image1_input = gr.Image(type="pil", label="Upload First Image")
 
1764
  outputs=save_status_dual
1765
  )
1766
 
1767
+ # Folder Analysis tab
1768
  with gr.Tab("Folder Analysis"):
1769
  gr.Markdown("## Analyze all images and PDFs in a folder")
1770
  gr.Markdown("""
 
1894
  yield folder_status_msg, ""
1895
  except:
1896
  pass
1897
+
1898
  # Run analysis
1899
  folder_status_msg = "Processing images... (this may take several minutes)"
1900
  yield folder_status_msg, ""
 
1941
  outputs=[save_status_folder]
1942
  )
1943
 
1944
+ # Saved Outputs tab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1945
  with gr.Tab("Saved Outputs"):
1946
  refresh_btn = gr.Button("Refresh File List")
1947
  file_list = gr.Markdown(value=list_output_files())