<｜begin▁of▁sentence｜>### Instruction:
Given the High-energy theory collaborations graph which you can read from a GML file named hep-th.gml, can you use the threshold clustering function in cdlib with a median threshold to perform community detection? And can you provide a JSON representation of the detected communities?
### Response:
import networkx as nx
from cdlib import algorithms
import numpy as np

# Read the graph from a gml file
G = nx.read_gml('hep-th.gml')

# Apply Threshold Clustering algorithm with a median threshold
communities = algorithms.threshold_clustering(G, threshold_function=np.median)

# Get the JSON representation of the detected communities
communities_json = communities.to_json()

print(communities_json)
<|EOT|>
