<commit_before>from flask import Flask, render_template, request, url_for, redirect
from summarize import summarize
import requests
from lxml import etree
from bs4 import BeautifulSoup as BS

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('tldrmed.html')

@app.route('/<int:pmid>')
def get_summary(pmid=None):
    r = requests.get('http://eutils.ncbi.nlm.nih.gov/entrez/eutils/'
                       'elink.fcgi?dbfrom=pubmed&id=%d&cmd=prlinks'
                       '&retmode=json' % pmid)
    
    body = None
    if r.status_code == 200:
        xml = etree.fromstring(r.text)
        try:
            url = xml.xpath('//Url')[0].text
        except:
            return('PubMed provided no fulltext URL for PMID %d' %pmid)
        full_text_r = requests.get(url)
        article = BS(full_text_r.text)
        paragraphs = article.findAll(['p'])
        body = ' '.join([p.text for p in paragraphs])

    return summarize(body, pmid)

@app.route('/search', methods=['POST', 'GET'])
def search():
    error = None
    if request.method == 'POST':
        pmid = request.form['pmid']
        return redirect('/'+pmid)
    else:
        return 'Method not available'

if __name__ == '__main__':
    app.run(debug=True)<commit_msg>make server visible globally<commit_after>from flask import Flask, render_template, request, url_for, redirect
from summarize import summarize
import requests
from lxml import etree
from bs4 import BeautifulSoup as BS

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('tldrmed.html')

@app.route('/<int:pmid>')
def get_summary(pmid=None):
    r = requests.get('http://eutils.ncbi.nlm.nih.gov/entrez/eutils/'
                       'elink.fcgi?dbfrom=pubmed&id=%d&cmd=prlinks'
                       '&retmode=json' % pmid)
    
    body = None
    if r.status_code == 200:
        xml = etree.fromstring(r.text)
        try:
            url = xml.xpath('//Url')[0].text
        except:
            return('PubMed provided no fulltext URL for PMID %d' %pmid)
        full_text_r = requests.get(url)
        article = BS(full_text_r.text)
        paragraphs = article.findAll(['p'])
        body = ' '.join([p.text for p in paragraphs])

    return summarize(body, pmid)

@app.route('/search', methods=['POST', 'GET'])
def search():
    error = None
    if request.method == 'POST':
        pmid = request.form['pmid']
        return redirect('/'+pmid)
    else:
        return 'Method not available'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
{'fraction_non_alphanumeric': 0.14083954491957631, 'fraction_numerical': 0.005492349941153394, 'mean_word_length': 2.6796536796536796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4767157', 'n_tokens_mistral': 859, 'n_tokens_neox': 826, 'n_words': 196}