Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
st.set_page_config(
|
5 |
+
page_title="Virgil Engine | Mathematical Computation",
|
6 |
+
page_icon="🧮",
|
7 |
+
layout="wide",
|
8 |
+
initial_sidebar_state="collapsed"
|
9 |
+
)
|
10 |
+
|
11 |
+
st.markdown("""
|
12 |
+
<style>
|
13 |
+
[data-testid="stHeader"] {
|
14 |
+
background-color: rgba(255, 255, 255, 0);
|
15 |
+
}
|
16 |
+
|
17 |
+
.main-container {
|
18 |
+
max-width: 1200px;
|
19 |
+
margin: 0 auto;
|
20 |
+
padding: 2rem;
|
21 |
+
}
|
22 |
+
|
23 |
+
.title-container {
|
24 |
+
text-align: center;
|
25 |
+
margin-bottom: 3rem;
|
26 |
+
}
|
27 |
+
|
28 |
+
.stButton > button {
|
29 |
+
background-color: #0066cc;
|
30 |
+
color: white;
|
31 |
+
border: none;
|
32 |
+
border-radius: 6px;
|
33 |
+
padding: 0.5rem 1rem;
|
34 |
+
font-weight: 500;
|
35 |
+
}
|
36 |
+
|
37 |
+
footer {
|
38 |
+
text-align: center;
|
39 |
+
padding: 2rem;
|
40 |
+
color: #666;
|
41 |
+
font-size: 0.9rem;
|
42 |
+
}
|
43 |
+
</style>
|
44 |
+
""", unsafe_allow_html=True)
|
45 |
+
|
46 |
+
st.title("Virgil Computational Engine")
|
47 |
+
st.markdown("""
|
48 |
+
<p style='font-size: 1.2rem; margin-bottom: 2rem;'>
|
49 |
+
Advanced Mathematical Computation & Problem Solving
|
50 |
+
</p>
|
51 |
+
""", unsafe_allow_html=True)
|
52 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
53 |
+
|
54 |
+
main_container = st.container()
|
55 |
+
|
56 |
+
with main_container:
|
57 |
+
left_col, right_col = st.columns([6, 4])
|
58 |
+
|
59 |
+
with left_col:
|
60 |
+
st.markdown("### Mathematical Query")
|
61 |
+
|
62 |
+
mode = st.radio(
|
63 |
+
"Select Computation Mode",
|
64 |
+
options=["Mode 1", "Mode 2"],
|
65 |
+
index=0
|
66 |
+
)
|
67 |
+
|
68 |
+
query = st.text_area(
|
69 |
+
"Math Question",
|
70 |
+
height=150,
|
71 |
+
placeholder="Enter your mathematical expression here...\nExample: Solve x^2 + 2x + 1 = 0",
|
72 |
+
key="query_input"
|
73 |
+
)
|
74 |
+
|
75 |
+
if st.button("Solve Expression", type="primary", use_container_width=True):
|
76 |
+
if not query:
|
77 |
+
st.error("Please enter a mathematical expression.")
|
78 |
+
else:
|
79 |
+
try:
|
80 |
+
with st.spinner("Computing solution..."):
|
81 |
+
mode_num = int(mode.split("Mode ")[1])
|
82 |
+
|
83 |
+
url = "https://virgil.ruben-roy.com/v1/process"
|
84 |
+
headers = {'Content-Type': 'application/json'}
|
85 |
+
data = {"query": query, "mode": mode_num}
|
86 |
+
|
87 |
+
response = requests.post(
|
88 |
+
url,
|
89 |
+
json=data,
|
90 |
+
headers=headers,
|
91 |
+
verify=False,
|
92 |
+
timeout=10
|
93 |
+
)
|
94 |
+
|
95 |
+
if response.status_code == 200:
|
96 |
+
result = response.json()
|
97 |
+
|
98 |
+
st.markdown("#### Solution")
|
99 |
+
st.latex(result['solution'])
|
100 |
+
|
101 |
+
except requests.exceptions.Timeout:
|
102 |
+
st.error("⚠️ Request timed out. Please try again.")
|
103 |
+
except requests.exceptions.RequestException as e:
|
104 |
+
st.error(f"⚠️ Connection error: {str(e)}")
|
105 |
+
except Exception as e:
|
106 |
+
st.error(f"⚠️ An unexpected error occurred: {str(e)}")
|
107 |
+
|
108 |
+
with right_col:
|
109 |
+
with st.expander("About Virgil Engine", expanded=True):
|
110 |
+
st.markdown("""
|
111 |
+
Virgil is a mathematical computation engine designed
|
112 |
+
to solve complex mathematical problems.
|
113 |
+
|
114 |
+
Developed by Ruben Roy, 2025.
|
115 |
+
""")
|
116 |
+
|
117 |
+
with st.expander("Computation Modes", expanded=True):
|
118 |
+
st.markdown("""
|
119 |
+
Virgil has 2 computational modes, they perform differently depending on what you want to do with it. If you get an unexpected or disappointing output from a specific mode, try switching to the other mode.
|
120 |
+
""")
|
121 |
+
|
122 |
+
with st.expander("How to Use", expanded=True):
|
123 |
+
st.markdown("""
|
124 |
+
1. First, select the mode you'd like to use.
|
125 |
+
2. Then, enter your query and type your mathematical expression
|
126 |
+
3. Finally click 'Solve Expression' to get your solution
|
127 |
+
|
128 |
+
Try using clear, standard mathematical notation for the best results.
|
129 |
+
""")
|
130 |
+
|
131 |
+
st.markdown("---")
|
132 |
+
st.markdown("""
|
133 |
+
<footer>
|
134 |
+
<p>© Ruben Roy 2025. All rights reserved.</p>
|
135 |
+
</footer>
|
136 |
+
""", unsafe_allow_html=True)
|