vansh9878 commited on
Commit
6fdb75f
·
1 Parent(s): 825e978

donee hopefully

Browse files
Files changed (3) hide show
  1. app.py +100 -0
  2. requirements.txt +21 -0
  3. space.yaml +4 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify, send_file
2
+ from flask_cors import CORS
3
+ import os
4
+ from langchain_folder.main import ReturnKeywordsfromPrompt
5
+ from dotenv import load_dotenv
6
+ import pandas as pd
7
+ import matplotlib.pyplot as plt
8
+ import seaborn as sns
9
+
10
+ load_dotenv()
11
+
12
+ app = Flask(__name__)
13
+ CORS(app)
14
+
15
+ CSV_FILE_PATH = os.getenv('file_path')
16
+ GRAPH_DIR = './static/graphs'
17
+
18
+
19
+ @app.route('/api/search', methods=['POST'])
20
+ def search():
21
+ data = request.get_json()
22
+ query = data.get('query', '')
23
+ keywords = ReturnKeywordsfromPrompt(query)
24
+ return jsonify({"status": "success", "queryReceived": query})
25
+
26
+
27
+ def generate_graphs_from_csv(csv_path, output_dir):
28
+ df = pd.read_csv(csv_path)
29
+ os.makedirs(output_dir, exist_ok=True)
30
+
31
+ numeric_cols = df.select_dtypes(include='number').columns.tolist()
32
+ categorical_cols = df.select_dtypes(include='object').columns.tolist()
33
+ graph_paths = []
34
+ print (categorical_cols)
35
+
36
+ if len(numeric_cols) >= 1:
37
+ plt.figure(figsize=(4, 3))
38
+ sns.histplot(df[numeric_cols[0]], kde=True)
39
+ plt.title(f'{numeric_cols[0]} Distribution')
40
+ plt.tight_layout()
41
+ path = f'{output_dir}/graph_1_hist.png'
42
+ plt.savefig(path)
43
+ graph_paths.append(path)
44
+
45
+ if len(numeric_cols) >= 2 and categorical_cols:
46
+ plt.figure(figsize=(4, 3))
47
+ sns.boxplot(data=df, x=categorical_cols[0], y=numeric_cols[1])
48
+ plt.title(f'{numeric_cols[1]} by {categorical_cols[0]}')
49
+ plt.tight_layout()
50
+ path = f'{output_dir}/graph_2_box.png'
51
+ plt.savefig(path)
52
+ graph_paths.append(path)
53
+
54
+ if categorical_cols:
55
+ plt.figure(figsize=(4, 3))
56
+ sns.countplot(data=df, x=categorical_cols[0])
57
+ plt.title(f'{categorical_cols[0]} Distribution')
58
+ plt.tight_layout()
59
+ path = f'{output_dir}/graph_3_count.png'
60
+ plt.savefig(path)
61
+ graph_paths.append(path)
62
+
63
+ if len(numeric_cols) >= 2:
64
+ plt.figure(figsize=(4, 3))
65
+ sns.scatterplot(data=df, x=numeric_cols[0], y=numeric_cols[1])
66
+ plt.title(f'{numeric_cols[0]} vs {numeric_cols[1]}')
67
+ plt.tight_layout()
68
+ path = f'{output_dir}/graph_4_scatter.png'
69
+ plt.savefig(path)
70
+ graph_paths.append(path)
71
+
72
+ return graph_paths
73
+
74
+
75
+ @app.route('/api/get_csv', methods=['GET'])
76
+ def get_csv():
77
+ try:
78
+ if not os.path.exists(CSV_FILE_PATH):
79
+ return jsonify({"error": "CSV file not found"}), 404
80
+ with open(CSV_FILE_PATH, "r", encoding="utf-8") as f:
81
+ return f.read(), 200, {
82
+ "Content-Type": "text/csv",
83
+ "Content-Disposition": "inline; filename=dataset.csv"
84
+ }
85
+ except Exception as e:
86
+ return jsonify({"error": str(e)}), 500
87
+
88
+
89
+ @app.route('/api/download_csv', methods=['GET'])
90
+ def download_csv():
91
+ return send_file(CSV_FILE_PATH, as_attachment=True)
92
+
93
+
94
+ @app.route('/api/get_graphs', methods=['GET'])
95
+ def get_graphs():
96
+ paths = generate_graphs_from_csv(CSV_FILE_PATH, GRAPH_DIR)
97
+ return jsonify({"graphs": [p.replace("./static", "/static") for p in paths]})
98
+
99
+ if __name__ == '__main__':
100
+ app.run(host="0.0.0.0", port=7860)
requirements.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ numpy
4
+ pandas
5
+ spacy
6
+ keras
7
+ tensorflow
8
+ scikit-learn
9
+ en-core-web-lg @ https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.8.0/en_core_web_lg-3.8.0.tar.gz
10
+ langchain_groq
11
+ langchain_core
12
+ selenium
13
+ openml
14
+ openai
15
+ rapidfuzz
16
+ matplotlib
17
+ seaborn
18
+ flask
19
+ google
20
+ datasets
21
+ kaggle
space.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ runtime: docker
2
+ docker:
3
+ ports: 7860
4
+ cmd: ["flask", "run", "--host=0.0.0.0", "--port=7860"]