File size: 1,459 Bytes
60f68c4
 
e7b4bfb
 
60f68c4
 
 
 
 
 
 
 
 
 
 
 
 
0b0ca93
 
60f68c4
0b0ca93
bd4d5c3
60f68c4
bd4d5c3
60f68c4
 
e7b4bfb
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from typing import List
from quickchart import QuickChart
import pandas as pd
from utils import TEMP_DIR

def chart_generation_func(queries: List[str], session_hash):
    print("CHART GENERATION")
    query_dict = queries[0]
    print(query_dict)

    qc = QuickChart()
    qc.width = 1000
    qc.height = 500

    # Config can be set as a string or as a nested dict
    qc.config = query_dict

    url_id = qc.get_short_url().rsplit('/', 1)[-1]
    url_base = qc.get_url_base()
    # You can get the chart URL...
    interactive_url = url_base + '/chart-maker/view/' + url_id
    edit_url = url_base + '/chart-maker/edit/' + url_id

    iframe = '<div style=overflow:auto;><iframe\n    scrolling="yes"\n    width="1000px"\n    height="500px"\n    src="' + interactive_url + '"\n    frameborder="0"\n    allowfullscreen\n></iframe>\n <p>Edit, share, and download this graph <a target="_blank" href="' + edit_url + '">here</a></p></div>'

    return {"reply": iframe}

def table_generation_func(data: List[str], session_hash):
    dir_path = TEMP_DIR / str(session_hash)
    print("TABLE GENERATION")
    print(data)
    df = pd.DataFrame(data)
    csv_path = f'{dir_path}/data.csv'
    df.to_csv(csv_path)
    download_path = f'gradio_api/file/temp/{session_hash}/data.csv'
    html_table = df.to_html() + f'<p>Download as a <a href="{download_path}">CSV</a></p>'
    print(html_table)

    return {"reply": html_table}