Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,9 @@ import requests
|
|
| 6 |
# Add the 'utils' directory to sys.path so Python can find modules within it
|
| 7 |
sys.path.append(os.path.join(os.path.dirname(__file__), "utils"))
|
| 8 |
|
| 9 |
-
# Importing the necessary function
|
| 10 |
from model_inference import generate_forex_signals
|
| 11 |
-
from config import RISK_LEVELS # Assuming config.py
|
| 12 |
|
| 13 |
# Streamlit page configuration
|
| 14 |
st.set_page_config(page_title="AI Forex Bot", page_icon=":guardsman:", layout="wide")
|
|
@@ -16,57 +16,58 @@ st.set_page_config(page_title="AI Forex Bot", page_icon=":guardsman:", layout="w
|
|
| 16 |
# Title of the application
|
| 17 |
st.title("AI Forex Trading Bot")
|
| 18 |
|
| 19 |
-
# Description
|
| 20 |
st.markdown("""
|
| 21 |
-
This AI-powered Forex Bot provides
|
| 22 |
-
|
| 23 |
""")
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Sidebar for user inputs
|
| 26 |
st.sidebar.header("User Input")
|
| 27 |
|
| 28 |
-
# Get user trading capital
|
| 29 |
trading_capital = st.sidebar.number_input("Enter Trading Capital (USD)", min_value=1, max_value=10000, value=1000)
|
| 30 |
|
| 31 |
-
# Get user market risk level
|
| 32 |
market_risk = st.sidebar.selectbox("Select Market Risk Level", options=["Low", "Medium", "High"])
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
try:
|
| 37 |
-
# Get the public IP address of the user
|
| 38 |
-
response = requests.get(f'https://ipinfo.io?token=37b621e95809fa')
|
| 39 |
-
data = response.json()
|
| 40 |
-
|
| 41 |
-
# Extract the timezone information from the response
|
| 42 |
-
user_timezone = data['timezone']
|
| 43 |
-
return user_timezone
|
| 44 |
-
except Exception as e:
|
| 45 |
-
print(f"Error fetching timezone: {e}")
|
| 46 |
-
return 'UTC' # Fallback to UTC if there's an error
|
| 47 |
-
|
| 48 |
-
# Get user's timezone automatically using IP address
|
| 49 |
-
user_timezone = get_user_timezone()
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
st.write(f"**Trading Capital**: ${trading_capital}")
|
| 53 |
-
st.write(f"**Market Risk Level**: {market_risk}")
|
| 54 |
-
st.write(f"**Timezone**: {user_timezone}")
|
| 55 |
-
|
| 56 |
-
# When user presses the "Get Trading Signals" button, run the model inference
|
| 57 |
if st.sidebar.button("Get Trading Signals"):
|
| 58 |
-
# Call the function to generate forex signals from model_inference.py
|
| 59 |
try:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
st.
|
| 66 |
-
st.write(f"**
|
| 67 |
-
st.write(f"**
|
| 68 |
-
st.write(f"**
|
|
|
|
|
|
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
except Exception as e:
|
| 71 |
st.error(f"Error: {str(e)}")
|
| 72 |
|
|
|
|
|
|
| 6 |
# Add the 'utils' directory to sys.path so Python can find modules within it
|
| 7 |
sys.path.append(os.path.join(os.path.dirname(__file__), "utils"))
|
| 8 |
|
| 9 |
+
# Importing the necessary function
|
| 10 |
from model_inference import generate_forex_signals
|
| 11 |
+
from config import RISK_LEVELS # Assuming config.py defines risk levels if needed
|
| 12 |
|
| 13 |
# Streamlit page configuration
|
| 14 |
st.set_page_config(page_title="AI Forex Bot", page_icon=":guardsman:", layout="wide")
|
|
|
|
| 16 |
# Title of the application
|
| 17 |
st.title("AI Forex Trading Bot")
|
| 18 |
|
| 19 |
+
# Description
|
| 20 |
st.markdown("""
|
| 21 |
+
This AI-powered Forex Bot provides trading signals for multiple currency pairs: EUR/USD, GBP/USD, and USD/JPY.
|
| 22 |
+
Enter your trading capital and select a risk level to get recommendations.
|
| 23 |
""")
|
| 24 |
|
| 25 |
+
# Automatically fetch the user's timezone using IPInfo API
|
| 26 |
+
access_token = "37b621e95809fa" # Replace with your actual IPInfo API token
|
| 27 |
+
try:
|
| 28 |
+
response = requests.get(f"https://ipinfo.io/json?token={access_token}")
|
| 29 |
+
response.raise_for_status()
|
| 30 |
+
user_timezone = response.json().get("timezone", "UTC")
|
| 31 |
+
except requests.exceptions.RequestException:
|
| 32 |
+
user_timezone = "UTC" # Default to UTC if the API call fails
|
| 33 |
+
|
| 34 |
# Sidebar for user inputs
|
| 35 |
st.sidebar.header("User Input")
|
| 36 |
|
| 37 |
+
# Get user trading capital
|
| 38 |
trading_capital = st.sidebar.number_input("Enter Trading Capital (USD)", min_value=1, max_value=10000, value=1000)
|
| 39 |
|
| 40 |
+
# Get user market risk level
|
| 41 |
market_risk = st.sidebar.selectbox("Select Market Risk Level", options=["Low", "Medium", "High"])
|
| 42 |
|
| 43 |
+
# Display the detected timezone
|
| 44 |
+
st.sidebar.write(f"**Detected Timezone**: {user_timezone}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# When the user presses the button, generate trading signals
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if st.sidebar.button("Get Trading Signals"):
|
|
|
|
| 48 |
try:
|
| 49 |
+
# Generate signals
|
| 50 |
+
signals = generate_forex_signals(trading_capital, market_risk, user_timezone)
|
| 51 |
+
|
| 52 |
+
# Display the best signal
|
| 53 |
+
best_signal = signals["best_signal"]
|
| 54 |
+
st.subheader("Best Recommended Forex Trade")
|
| 55 |
+
st.write(f"**Currency Pair**: {best_signal['currency_pair']}")
|
| 56 |
+
st.write(f"**Entry Time**: {best_signal['entry_time']}")
|
| 57 |
+
st.write(f"**Exit Time**: {best_signal['exit_time']}")
|
| 58 |
+
st.write(f"**ROI**: {best_signal['roi']}%")
|
| 59 |
+
st.write(f"**Signal Strength**: {best_signal['signal_strength']}")
|
| 60 |
|
| 61 |
+
# Display all signals
|
| 62 |
+
st.subheader("All Generated Signals")
|
| 63 |
+
for signal in signals["all_signals"]:
|
| 64 |
+
st.write(f"**Currency Pair**: {signal['currency_pair']}")
|
| 65 |
+
st.write(f"**Entry Time**: {signal['entry_time']}")
|
| 66 |
+
st.write(f"**Exit Time**: {signal['exit_time']}")
|
| 67 |
+
st.write(f"**ROI**: {signal['roi']}%")
|
| 68 |
+
st.write(f"**Signal Strength**: {signal['signal_strength']}")
|
| 69 |
+
st.markdown("---")
|
| 70 |
except Exception as e:
|
| 71 |
st.error(f"Error: {str(e)}")
|
| 72 |
|
| 73 |
+
|