Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	update
Browse files- README.md +4 -3
- app.py +57 -39
- requirements.txt +0 -1
    	
        README.md
    CHANGED
    
    | @@ -1,9 +1,10 @@ | |
| 1 | 
             
            ---
         | 
| 2 | 
             
            title: CLIP GamePhysics
         | 
| 3 | 
            -
            emoji:  | 
| 4 | 
            -
            colorFrom:  | 
| 5 | 
            -
            colorTo:  | 
| 6 | 
             
            sdk: gradio
         | 
|  | |
| 7 | 
             
            app_file: app.py
         | 
| 8 | 
             
            pinned: false
         | 
| 9 | 
             
            ---
         | 
|  | |
| 1 | 
             
            ---
         | 
| 2 | 
             
            title: CLIP GamePhysics
         | 
| 3 | 
            +
            emoji: 🚚
         | 
| 4 | 
            +
            colorFrom: red
         | 
| 5 | 
            +
            colorTo: blue
         | 
| 6 | 
             
            sdk: gradio
         | 
| 7 | 
            +
            sdk_version: 3.0.5
         | 
| 8 | 
             
            app_file: app.py
         | 
| 9 | 
             
            pinned: false
         | 
| 10 | 
             
            ---
         | 
    	
        app.py
    CHANGED
    
    | @@ -1,4 +1,7 @@ | |
|  | |
| 1 | 
             
            import os
         | 
|  | |
|  | |
| 2 | 
             
            import pickle
         | 
| 3 | 
             
            from collections import Counter
         | 
| 4 | 
             
            from glob import glob
         | 
| @@ -13,30 +16,35 @@ from tqdm import tqdm | |
| 13 |  | 
| 14 | 
             
            from SimSearch import FaissCosineNeighbors
         | 
| 15 |  | 
|  | |
|  | |
|  | |
| 16 | 
             
            # DOWNLOAD THE DATASET and Files
         | 
| 17 | 
            -
            gdown. | 
| 18 | 
            -
                "https://static.taesiri.com/gamephysics/GTAV-Videos.zip",
         | 
| 19 | 
            -
                 | 
| 20 | 
             
                quiet=False,
         | 
|  | |
| 21 | 
             
            )
         | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
                 | 
|  | |
| 25 | 
             
                quiet=False,
         | 
|  | |
| 26 | 
             
            )
         | 
| 27 |  | 
| 28 | 
             
            # EXTRACT
         | 
| 29 | 
            -
             | 
| 30 | 
             
            torchvision.datasets.utils.extract_archive(
         | 
| 31 | 
             
                from_path="GTAV-Videos.zip", to_path="Videos/", remove_finished=False
         | 
| 32 | 
             
            )
         | 
| 33 | 
             
            # EXTRACT
         | 
| 34 | 
            -
             | 
| 35 | 
             
            torchvision.datasets.utils.extract_archive(
         | 
| 36 | 
             
                from_path="GTA-V-Embeddings.zip",
         | 
| 37 | 
             
                to_path="Embeddings/VIT32/",
         | 
| 38 | 
             
                remove_finished=False,
         | 
| 39 | 
             
            )
         | 
|  | |
| 40 | 
             
            # Initialize CLIP model
         | 
| 41 | 
             
            clip.available_models()
         | 
| 42 |  | 
| @@ -147,46 +155,44 @@ def gradio_search(query, game_name, selected_model, aggregator, pool_size, k=6): | |
| 147 | 
             
                for v in relevant_videos:
         | 
| 148 | 
             
                    results.append(v)
         | 
| 149 | 
             
                    sid = v.split("/")[-1].split(".")[0]
         | 
| 150 | 
            -
                    results.append( | 
|  | |
|  | |
|  | |
|  | |
| 151 | 
             
                return results
         | 
| 152 |  | 
| 153 |  | 
| 154 | 
             
            def main():
         | 
| 155 | 
             
                list_of_games = ["Grand Theft Auto V"]
         | 
| 156 |  | 
| 157 | 
            -
                title = "CLIP + GamePhysics - Searching dataset of Gameplay bugs"
         | 
| 158 | 
            -
                description = "Enter your query and select the game you want to search. The results will be displayed in the console."
         | 
| 159 | 
            -
                article = """
         | 
| 160 | 
            -
              This demo shows how to use the CLIP model to search for gameplay bugs in a video game.
         | 
| 161 | 
            -
              """
         | 
| 162 | 
            -
             | 
| 163 | 
             
                # GRADIO APP
         | 
| 164 | 
            -
                 | 
| 165 | 
             
                    fn=gradio_search,
         | 
| 166 | 
             
                    inputs=[
         | 
| 167 | 
            -
                        gr. | 
| 168 | 
             
                            lines=1,
         | 
| 169 | 
             
                            placeholder="Search Query",
         | 
| 170 | 
            -
                             | 
| 171 | 
            -
                            label= | 
| 172 | 
             
                        ),
         | 
| 173 | 
            -
                        gr. | 
| 174 | 
            -
                        gr. | 
| 175 | 
            -
                        gr. | 
| 176 | 
            -
                        gr. | 
| 177 | 
             
                    ],
         | 
| 178 | 
             
                    outputs=[
         | 
| 179 | 
            -
                        gr. | 
| 180 | 
            -
                        gr. | 
| 181 | 
            -
                        gr. | 
| 182 | 
            -
                        gr. | 
| 183 | 
            -
                        gr. | 
| 184 | 
            -
                        gr. | 
| 185 | 
            -
                        gr. | 
| 186 | 
            -
                        gr. | 
| 187 | 
            -
                        gr. | 
| 188 | 
            -
                        gr. | 
| 189 | 
            -
                        gr. | 
| 190 | 
             
                    ],
         | 
| 191 | 
             
                    examples=[
         | 
| 192 | 
             
                        ["A red car", list_of_games[0], "ViT-B/32", "Top-K", 1000],
         | 
| @@ -211,13 +217,25 @@ def main(): | |
| 211 | 
             
                        ["A car stuck in a rock", list_of_games[0], "ViT-B/32", "Majority", 1000],
         | 
| 212 | 
             
                        ["A car stuck in a tree", list_of_games[0], "ViT-B/32", "Majority", 1000],
         | 
| 213 | 
             
                    ],
         | 
| 214 | 
            -
                    title=title,
         | 
| 215 | 
            -
                    description=description,
         | 
| 216 | 
            -
                    article=article,
         | 
| 217 | 
            -
                    enable_queue=True,
         | 
| 218 | 
             
                )
         | 
| 219 |  | 
| 220 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 221 |  | 
| 222 |  | 
| 223 | 
             
            if __name__ == "__main__":
         | 
|  | |
| 1 | 
            +
            import csv
         | 
| 2 | 
             
            import os
         | 
| 3 | 
            +
            import random
         | 
| 4 | 
            +
            import sys
         | 
| 5 | 
             
            import pickle
         | 
| 6 | 
             
            from collections import Counter
         | 
| 7 | 
             
            from glob import glob
         | 
|  | |
| 16 |  | 
| 17 | 
             
            from SimSearch import FaissCosineNeighbors
         | 
| 18 |  | 
| 19 | 
            +
            csv.field_size_limit(sys.maxsize)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
             | 
| 22 | 
             
            # DOWNLOAD THE DATASET and Files
         | 
| 23 | 
            +
            gdown.cached_download(
         | 
| 24 | 
            +
                url="https://static.taesiri.com/gamephysics/GTAV-Videos.zip",
         | 
| 25 | 
            +
                path="./GTAV-Videos.zip",
         | 
| 26 | 
             
                quiet=False,
         | 
| 27 | 
            +
                md5="e961093bc032f579de060ed65564b4c3",
         | 
| 28 | 
             
            )
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            gdown.cached_download(
         | 
| 31 | 
            +
                url="https://static.taesiri.com/gamephysics/mini-GTA-V-Embeddings.zip",
         | 
| 32 | 
            +
                path="./GTA-V-Embeddings.zip",
         | 
| 33 | 
             
                quiet=False,
         | 
| 34 | 
            +
                md5="b1228503d5a89eef7e35e2cbf86b2fc0",
         | 
| 35 | 
             
            )
         | 
| 36 |  | 
| 37 | 
             
            # EXTRACT
         | 
|  | |
| 38 | 
             
            torchvision.datasets.utils.extract_archive(
         | 
| 39 | 
             
                from_path="GTAV-Videos.zip", to_path="Videos/", remove_finished=False
         | 
| 40 | 
             
            )
         | 
| 41 | 
             
            # EXTRACT
         | 
|  | |
| 42 | 
             
            torchvision.datasets.utils.extract_archive(
         | 
| 43 | 
             
                from_path="GTA-V-Embeddings.zip",
         | 
| 44 | 
             
                to_path="Embeddings/VIT32/",
         | 
| 45 | 
             
                remove_finished=False,
         | 
| 46 | 
             
            )
         | 
| 47 | 
            +
             | 
| 48 | 
             
            # Initialize CLIP model
         | 
| 49 | 
             
            clip.available_models()
         | 
| 50 |  | 
|  | |
| 155 | 
             
                for v in relevant_videos:
         | 
| 156 | 
             
                    results.append(v)
         | 
| 157 | 
             
                    sid = v.split("/")[-1].split(".")[0]
         | 
| 158 | 
            +
                    results.append(
         | 
| 159 | 
            +
                        f'<a href="https://www.reddit.com/r/GamePhysics/comments/{sid}/" target="_blank">Link to the post</a>'
         | 
| 160 | 
            +
                    )
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                print(f"found {len(results)} results")
         | 
| 163 | 
             
                return results
         | 
| 164 |  | 
| 165 |  | 
| 166 | 
             
            def main():
         | 
| 167 | 
             
                list_of_games = ["Grand Theft Auto V"]
         | 
| 168 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 169 | 
             
                # GRADIO APP
         | 
| 170 | 
            +
                main = gr.Interface(
         | 
| 171 | 
             
                    fn=gradio_search,
         | 
| 172 | 
             
                    inputs=[
         | 
| 173 | 
            +
                        gr.Textbox(
         | 
| 174 | 
             
                            lines=1,
         | 
| 175 | 
             
                            placeholder="Search Query",
         | 
| 176 | 
            +
                            value="A person flying in the air",
         | 
| 177 | 
            +
                            label="Query",
         | 
| 178 | 
             
                        ),
         | 
| 179 | 
            +
                        gr.Radio(list_of_games, label="Game To Search"),
         | 
| 180 | 
            +
                        gr.Radio(["ViT-B/32"], label="MODEL"),
         | 
| 181 | 
            +
                        gr.Radio(["Majority", "Top-K"], label="Aggregator"),
         | 
| 182 | 
            +
                        gr.Slider(300, 2000, label="Pool Size", value=1000),
         | 
| 183 | 
             
                    ],
         | 
| 184 | 
             
                    outputs=[
         | 
| 185 | 
            +
                        gr.Textbox(type="auto", label="Search Params"),
         | 
| 186 | 
            +
                        gr.Video(type="mp4", label="Result 1"),
         | 
| 187 | 
            +
                        gr.Markdown(),
         | 
| 188 | 
            +
                        gr.Video(type="mp4", label="Result 2"),
         | 
| 189 | 
            +
                        gr.Markdown(),
         | 
| 190 | 
            +
                        gr.Video(type="mp4", label="Result 3"),
         | 
| 191 | 
            +
                        gr.Markdown(),
         | 
| 192 | 
            +
                        gr.Video(type="mp4", label="Result 4"),
         | 
| 193 | 
            +
                        gr.Markdown(),
         | 
| 194 | 
            +
                        gr.Video(type="mp4", label="Result 5"),
         | 
| 195 | 
            +
                        gr.Markdown(),
         | 
| 196 | 
             
                    ],
         | 
| 197 | 
             
                    examples=[
         | 
| 198 | 
             
                        ["A red car", list_of_games[0], "ViT-B/32", "Top-K", 1000],
         | 
|  | |
| 217 | 
             
                        ["A car stuck in a rock", list_of_games[0], "ViT-B/32", "Majority", 1000],
         | 
| 218 | 
             
                        ["A car stuck in a tree", list_of_games[0], "ViT-B/32", "Majority", 1000],
         | 
| 219 | 
             
                    ],
         | 
|  | |
|  | |
|  | |
|  | |
| 220 | 
             
                )
         | 
| 221 |  | 
| 222 | 
            +
                blocks = gr.Blocks()
         | 
| 223 | 
            +
                with blocks:
         | 
| 224 | 
            +
             | 
| 225 | 
            +
                    gr.Markdown(
         | 
| 226 | 
            +
                        """
         | 
| 227 | 
            +
                    # CLIP + GamePhysics - Searching dataset of Gameplay bugs
         | 
| 228 | 
            +
                    Enter your query and select the game you want to search. The results will be displayed in the console.
         | 
| 229 | 
            +
                    This demo shows how to use the CLIP model to search for gameplay bugs in a video game.
         | 
| 230 | 
            +
                    """
         | 
| 231 | 
            +
                    )
         | 
| 232 | 
            +
             | 
| 233 | 
            +
                    gr.TabbedInterface([main], ["GTA V Demo"])
         | 
| 234 | 
            +
             | 
| 235 | 
            +
                blocks.launch(
         | 
| 236 | 
            +
                    debug=True,
         | 
| 237 | 
            +
                    enable_queue=True,
         | 
| 238 | 
            +
                )
         | 
| 239 |  | 
| 240 |  | 
| 241 | 
             
            if __name__ == "__main__":
         | 
    	
        requirements.txt
    CHANGED
    
    | @@ -20,7 +20,6 @@ fonttools==4.28.5 | |
| 20 | 
             
            ftfy==6.0.3
         | 
| 21 | 
             
            gitdb==4.0.9
         | 
| 22 | 
             
            GitPython==3.1.26
         | 
| 23 | 
            -
            gradio==2.7.0
         | 
| 24 | 
             
            idna==3.3
         | 
| 25 | 
             
            imageio==2.13.5
         | 
| 26 | 
             
            itsdangerous==2.0.1
         | 
|  | |
| 20 | 
             
            ftfy==6.0.3
         | 
| 21 | 
             
            gitdb==4.0.9
         | 
| 22 | 
             
            GitPython==3.1.26
         | 
|  | |
| 23 | 
             
            idna==3.3
         | 
| 24 | 
             
            imageio==2.13.5
         | 
| 25 | 
             
            itsdangerous==2.0.1
         | 

