aromidvar commited on
Commit
7cb58d4
·
verified ·
1 Parent(s): 3bf07bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -1
app.py CHANGED
@@ -3,6 +3,8 @@ from flask_sqlalchemy import SQLAlchemy
3
  import numpy as np
4
  import pandas as pd
5
  import xgboost as xgb
 
 
6
 
7
  app = Flask(__name__)
8
  app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://username:password@your-render-database-url/economic_data_db'
@@ -62,5 +64,49 @@ def get_economic_data():
62
  records = EconomicData.query.all() # Retrieve all records
63
  return jsonify({record.indicator: record.value for record in records})
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  if __name__ == '__main__':
66
- app.run(debug=True)
 
 
 
 
3
  import numpy as np
4
  import pandas as pd
5
  import xgboost as xgb
6
+ import gradio as gr
7
+ import threading
8
 
9
  app = Flask(__name__)
10
  app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://username:password@your-render-database-url/economic_data_db'
 
64
  records = EconomicData.query.all() # Retrieve all records
65
  return jsonify({record.indicator: record.value for record in records})
66
 
67
+ # Gradio UI function
68
+ def gradio_ui():
69
+ def query_api(query):
70
+ response = requests.post('http://localhost:5000/search', json={'query': query})
71
+ return response.json()
72
+
73
+ def predict_time_series(num_predictions):
74
+ response = requests.post('http://localhost:5000/predict', json={'num_predictions': num_predictions})
75
+ return response.json()["predictions"]
76
+
77
+ def retrieve_economic_data():
78
+ response = requests.get('http://localhost:5000/economic_data')
79
+ return response.json()
80
+
81
+ with gr.Blocks() as demo:
82
+ gr.Markdown("# Economic DataHub")
83
+ gr.Markdown("Welcome to the interactive Economic DataHub. Explore economic indicators, make predictions, and access detailed economic data.")
84
+
85
+ with gr.Tab("Search Economic Indicators"):
86
+ search_input = gr.Textbox(label="Search for Economic Terms:", placeholder="Enter an economic term...")
87
+ search_button = gr.Button("Search")
88
+ output_text = gr.Textbox(label="Results", interactive=False)
89
+
90
+ search_button.click(query_api, inputs=search_input, outputs=output_text)
91
+
92
+ with gr.Tab("Time Series Prediction"):
93
+ num_predictions = gr.Slider(minimum=1, maximum=30, step=1, label="Number of Days to Predict")
94
+ predict_button = gr.Button("Predict")
95
+ prediction_output = gr.Textbox(label="Predictions", interactive=False)
96
+
97
+ predict_button.click(predict_time_series, inputs=num_predictions, outputs=prediction_output)
98
+
99
+ with gr.Tab("Retrieve Economic Data"):
100
+ retrieve_button = gr.Button("Get Economic Data")
101
+ data_output = gr.Textbox(label="Economic Data", interactive=False)
102
+
103
+ retrieve_button.click(retrieve_economic_data, outputs=data_output)
104
+
105
+ demo.launch(server_name="0.0.0.0", server_port=7860, share=True) # Adjusted for Hugging Face Spaces
106
+
107
+ # Run the Flask app and Gradio UI in separate threads
108
  if __name__ == '__main__':
109
+ # Start the Flask app in a separate thread
110
+ threading.Thread(target=app.run).start()
111
+ # Start the Gradio UI
112
+ gradio_ui()