-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
46 lines (34 loc) · 1.42 KB
/
app.py
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
41
42
43
44
45
46
from flask import Flask, render_template, request, jsonify
import pandas as pd
from llm import load_astrollama_model, get_backstory_for_image
from main import search_object, load_data
from query import process_question
app = Flask(__name__)
windows_path = r"C:\Users\Anaki\OneDrive\Desktop\codingprojects\jwst\JWST-Project\Copy of Dataset - Sheet1 (1).csv"
wsl_path = '/mnt/c' + windows_path[2:].replace('\\', '/')
data = load_data(wsl_path)
tokenizer, model = load_astrollama_model
# Route for searching objects
@app.route('/')
def index():
return render_template('index.html')
def search():
object_name = request.json.get('object_name')
constellation = request.json.get('Constellation')
distance_range = request.json.get('object_name')
results = search_object(data, object_name, constellation, distance_range)
return jsonify(results.to_dict())
# Route for getting a backstory for an image
@app.route('/backstory', methods=['POST'])
def backstory():
image_data = request.json # Expecting image data (e.g., from frontend)
backstory = get_backstory_for_image(image_data, tokenizer, model)
return jsonify({"backstory": backstory})
# Route for processing NLP queries
@app.route('/query', methods=['POST'])
def query():
question = request.json.get('question')
result = process_question(question, data)
return jsonify({"result": result})
if __name__ == '__main__':
app.run(debug=True)