Saraay commited on
Commit
190fe76
·
verified ·
1 Parent(s): 5d4a772
Files changed (1) hide show
  1. app.py +2 -83
app.py CHANGED
@@ -204,6 +204,7 @@ class Equinix:
204
  Y.append(dataset[i + self.time_step, 0])
205
  return np.array(X), np.array(Y)
206
 
 
207
  def build_model(self):
208
  self.model = Sequential()
209
  self.model.add(LSTM(40, return_sequences=True, input_shape=(self.time_step, 1)))
@@ -680,88 +681,6 @@ ela.train_model()
680
 
681
 
682
 
683
- import matplotlib.pyplot as plt
684
- import gradio as gr
685
- from datetime import datetime
686
-
687
- def compare_models(date, money):
688
- input_data=date_to_days(date)
689
- uber_prediction = uber.predict_future(input_data)
690
- eq_prediction = eq.predict_future(input_data)
691
- ub_prediction = ub.predict_future(input_data)
692
- sfl_prediction = sfl.predict_future(input_data)
693
- ela_prediction = ela.predict_future(input_data)
694
-
695
- uber_current = uber.predict_future(1)
696
- eq_current =eq.predict_future(1)
697
- ub_current = ub.predict_future(1)
698
- sfl_current =sfl.predict_future(1)
699
- ela_current = ela.predict_future(1)
700
-
701
-
702
- uber_stocks = money / uber_current[-1][0]
703
- eq_stocks = money / eq_current[-1][0]
704
- ub_stocks= money / ub_current[-1][0]
705
- sfl_stocks = money / sfl_current[-1][0]
706
- ela_stocks= money / ela_current[-1][0]
707
-
708
- predictions = {
709
-
710
- "Uber": (uber_prediction[-1][0] - uber_current[-1][0]) * uber_stocks,
711
- "Equinix": (eq_prediction[-1][0] - eq_current[-1][0]) * eq_stocks,
712
- "Ubiquiti": (ub_prediction[-1][0] - ub_current[-1][0]) * ub_stocks,
713
- "SFL Corporation": (sfl_prediction[-1][0] - sfl_current[-1][0]) * sfl_stocks,
714
- "Envela Corporation": (ela_prediction[-1][0] - ela_current[-1][0]) * ela_stocks,
715
- }
716
- best_stock = max(predictions, key=predictions.get)
717
- best_profit = predictions[best_stock]
718
-
719
- best_prediction = f"Best stock company is {best_stock} with profit approximately {best_profit} $ and your total money is {best_profit + money} $"
720
- return best_stock, best_prediction
721
-
722
- def plot_for_user(stock_name, future_days):
723
- stock = None
724
-
725
- if stock_name == "Uber":
726
- stock = uber
727
- elif stock_name == "Equinix":
728
- stock = eq
729
- elif stock_name== "Ubiquiti":
730
- stock=ub
731
- elif stock_name == "SFL Corporation":
732
- stock = sfl
733
- elif stock_name== "Envela Corporation":
734
- stock=ela
735
-
736
-
737
- plt.figure(figsize=(14, 8))
738
- plt.plot(stock.dates, stock.data, label='Actual Stock Price')
739
- plt.xlabel('Date')
740
- plt.ylabel(f'{stock_name} Stock Price')
741
- plt.legend()
742
-
743
- return plt.gcf() # Return the current figure
744
-
745
- def combined_function(input_data, money):
746
- best_stock, best_prediction = compare_models(input_data, money)
747
- plot = plot_for_user(best_stock, input_data)
748
- return best_prediction, plot
749
-
750
-
751
- def date_to_days(date_str):
752
- target_date = datetime.strptime(date_str, '%Y-%m-%d')
753
- current_date = datetime.now()
754
- print(current_date)
755
- return (target_date - current_date ).days+1
756
-
757
- iface = gr.Interface(
758
- fn=combined_function,
759
- inputs=["text", "number"],
760
- outputs=["text", "plot"],
761
- )
762
-
763
- iface.launch(debug=True)
764
-
765
  import matplotlib.pyplot as plt
766
  import gradio as gr
767
  from datetime import datetime
@@ -858,7 +777,7 @@ def plot_for_user(stock_name, future_days):
858
  def combined_function(date, money ):
859
  best_stock, best_prediction = compare_models(date, money)
860
  if not best_stock:
861
- img = plt.imread('WhatsApp Image 2024-07-02 at 5.03.34 AM.jpeg')
862
  plt.imshow(img)
863
  plt.axis('off')
864
  plot = plt.gcf()
 
204
  Y.append(dataset[i + self.time_step, 0])
205
  return np.array(X), np.array(Y)
206
 
207
+
208
  def build_model(self):
209
  self.model = Sequential()
210
  self.model.add(LSTM(40, return_sequences=True, input_shape=(self.time_step, 1)))
 
681
 
682
 
683
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684
  import matplotlib.pyplot as plt
685
  import gradio as gr
686
  from datetime import datetime
 
777
  def combined_function(date, money ):
778
  best_stock, best_prediction = compare_models(date, money)
779
  if not best_stock:
780
+ img = plt.imread('haga.jpeg')
781
  plt.imshow(img)
782
  plt.axis('off')
783
  plot = plt.gcf()