<｜begin▁of▁sentence｜>### Instruction:
Given the novel 'Les Miserables' and its character interaction graph which you can read from a GML file named lesmis.gml, can you use the Louvain method provided by the cdlib library to perform community detection? And can you write the resulting community structure to a JSON file named communities.json?
### Response:
import networkx as nx
from cdlib import algorithms, readwrite

g = nx.read_gml('lesmis.gml')
coms = algorithms.louvain(g)
readwrite.write_community_json(coms, 'communities.json')
<|EOT|>
