JunchuanYu commited on
Commit
9aae2bd
·
1 Parent(s): 6e4d900

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -45
app.py CHANGED
@@ -14,55 +14,12 @@ import logging
14
  from huggingface_hub import login
15
  from huggingface_hub import Repository
16
  from huggingface_hub import hf_hub_download
17
- # os.system("python -m pip install --upgrade pip")
18
- # os.system("pip uninstall -y gradio")
19
- # os.system("pip install gradio==3.26.0")
20
 
21
  token = os.environ['HUB_TOKEN']
22
  loc =hf_hub_download(repo_id="JunchuanYu/files_for_segmentRS", filename="utils.py",repo_type="dataset",local_dir='.',token=token)
23
- print(loc)
24
  sys.path.append(loc)
25
  from utils import *
26
 
27
-
28
- matplotlib.pyplot.switch_backend('Agg') # for matplotlib to work in gradio
29
- #setup model
30
- sam_checkpoint = "sam_vit_h_4b8939.pth"
31
- device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # use GPU if available
32
- model_type = "vit_h"
33
- sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)
34
- sam.to(device=device)
35
- predictor = SamPredictor(sam)
36
- logging.basicConfig(filename="app.log", level=logging.INFO)
37
-
38
- title=(
39
- """
40
- # <p align="center"> Segment-RS 🛰️ <b>
41
- ## <p align="center"> A remote sensing interactive interpretation tools based on segment-anything (SAM 👍) <b>
42
- ### <p align="center"> YJC ([email protected]) 📧<b>
43
- """
44
- )
45
- description =(
46
- """
47
- Segment-RS is an interactive remote sensing interpretation tool that has been developed based on [SAM](https://github.com/facebookresearch/segment-anything). It allows for the real-time extraction of various remote sensing targets through interaction. Segment-RS is equipped with two interpretation models, namely, interactive extraction and automatic extraction.
48
- * Interactive extraction involves manually selecting samples (positive and negative) from the image to extract obvious targets. It should be emphasized that this manual interaction method is suitable for extracting an independent target in the scene and not suitable for extracting multiple targets of the same type at once as it is still under development.
49
- * Automatic extraction does not require any interaction, one can simply click the "Auto Segment" button to get the segmentation result. Additionally, the accuracy and granularity of segmentation can be adjusted through "Prediction Thresh" and "Points Per Side".
50
- """
51
- )
52
- descriptionend=(
53
- """
54
- <div align=center><img src="https://em-content.zobj.net/source/microsoft-teams/337/robot_1f916.png" style="width:5%;"></div>
55
- <br />
56
- <div align=center>you can follow the WeChat public account [45度科研人] and leave me a message! </div>
57
- <br />
58
- <div style="display:flex; justify-content:center;">
59
- <img src="https://dunazo.oss-cn-beijing.aliyuncs.com/blog/wechat-simple.png" style="margin-right:25px;width:200px;height:200px;">
60
- <div style="width:25px;"></div>
61
- <img src="https://dunazo.oss-cn-beijing.aliyuncs.com/blog/shoukuanma222.png" style="margin-left:25px;width:170px;height:190px;">
62
- </div>
63
- """
64
- )
65
-
66
  with gr.Blocks(theme='gradio/soft') as demo:
67
  gr.Markdown(title)
68
  with gr.Accordion("Instructions For User 👉", open=False):
@@ -105,11 +62,11 @@ with gr.Blocks(theme='gradio/soft') as demo:
105
  fn=auto_seg,
106
  inputs=[input_img,pred_iou_thresh,points_per_side],
107
  outputs=[output_img],
108
- cache_examples=True,examples_per_page=5)
109
 
110
  gr.Markdown(descriptionend)
111
  if __name__ == "__main__":
112
- demo.launch(debug=False,show_api=False,Share=True)
113
 
114
  # matplotlib.pyplot.switch_backend('Agg') # for matplotlib to work in gradio
115
  # #setup model
 
14
  from huggingface_hub import login
15
  from huggingface_hub import Repository
16
  from huggingface_hub import hf_hub_download
 
 
 
17
 
18
  token = os.environ['HUB_TOKEN']
19
  loc =hf_hub_download(repo_id="JunchuanYu/files_for_segmentRS", filename="utils.py",repo_type="dataset",local_dir='.',token=token)
 
20
  sys.path.append(loc)
21
  from utils import *
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  with gr.Blocks(theme='gradio/soft') as demo:
24
  gr.Markdown(title)
25
  with gr.Accordion("Instructions For User 👉", open=False):
 
62
  fn=auto_seg,
63
  inputs=[input_img,pred_iou_thresh,points_per_side],
64
  outputs=[output_img],
65
+ cache_examples=False,examples_per_page=5)
66
 
67
  gr.Markdown(descriptionend)
68
  if __name__ == "__main__":
69
+ demo.launch(debug=False,show_api=False)
70
 
71
  # matplotlib.pyplot.switch_backend('Agg') # for matplotlib to work in gradio
72
  # #setup model