Tassawar commited on
Commit
4bd75af
·
verified ·
1 Parent(s): 048a1e9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +192 -0
app.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PyPDF2 import PdfReader
3
+ from docx import Document
4
+ from pdf2image import convert_from_bytes
5
+ import pytesseract
6
+ from datetime import datetime
7
+ from PIL import Image
8
+ import io
9
+
10
+ # Configure Tesseract path (if needed)
11
+ # pytesseract.pytesseract.tesseract_cmd = r'/path/to/tesseract'
12
+
13
+ # Page Configuration
14
+ st.set_page_config(page_title="Everything Converter", page_icon="🔄", layout="centered")
15
+
16
+ # App Header
17
+ st.title("🔄 Everything Converter")
18
+ st.write("Your one-stop solution for all types of conversions!")
19
+
20
+ # Sidebar for Navigation
21
+ st.sidebar.title("Navigation")
22
+ conversion_type = st.sidebar.radio(
23
+ "Choose a Converter",
24
+ ["Unit Converter", "File Converter", "Image Converter", "Date and Time Converter", "Number System Converter"]
25
+ )
26
+
27
+ # Unit Converter
28
+ if conversion_type == "Unit Converter":
29
+ st.header("Unit Converter")
30
+ unit_category = st.selectbox("Select Unit Category", ["Length", "Weight", "Temperature"])
31
+
32
+ if unit_category == "Length":
33
+ length_units = ["Meters", "Kilometers", "Miles", "Feet", "Inches"]
34
+ from_unit = st.selectbox("From", length_units)
35
+ to_unit = st.selectbox("To", length_units)
36
+ value = st.number_input("Enter Value", min_value=0.0)
37
+
38
+ if st.button("Convert"):
39
+ # Conversion logic for length
40
+ conversions = {
41
+ "Meters": 1,
42
+ "Kilometers": 0.001,
43
+ "Miles": 0.000621371,
44
+ "Feet": 3.28084,
45
+ "Inches": 39.3701,
46
+ }
47
+ result = value * (conversions[to_unit] / conversions[from_unit])
48
+ st.success(f"Converted Value: **{result:.2f} {to_unit}**")
49
+
50
+ elif unit_category == "Weight":
51
+ weight_units = ["Kilograms", "Grams", "Pounds", "Ounces"]
52
+ from_unit = st.selectbox("From", weight_units)
53
+ to_unit = st.selectbox("To", weight_units)
54
+ value = st.number_input("Enter Value", min_value=0.0)
55
+
56
+ if st.button("Convert"):
57
+ # Conversion logic for weight
58
+ conversions = {
59
+ "Kilograms": 1,
60
+ "Grams": 1000,
61
+ "Pounds": 2.20462,
62
+ "Ounces": 35.274,
63
+ }
64
+ result = value * (conversions[to_unit] / conversions[from_unit])
65
+ st.success(f"Converted Value: **{result:.2f} {to_unit}**")
66
+
67
+ elif unit_category == "Temperature":
68
+ temp_units = ["Celsius", "Fahrenheit", "Kelvin"]
69
+ from_unit = st.selectbox("From", temp_units)
70
+ to_unit = st.selectbox("To", temp_units)
71
+ value = st.number_input("Enter Value", min_value=-273.15)
72
+
73
+ if st.button("Convert"):
74
+ # Conversion logic for temperature
75
+ if from_unit == "Celsius":
76
+ if to_unit == "Fahrenheit":
77
+ result = (value * 9/5) + 32
78
+ elif to_unit == "Kelvin":
79
+ result = value + 273.15
80
+ else:
81
+ result = value
82
+ elif from_unit == "Fahrenheit":
83
+ if to_unit == "Celsius":
84
+ result = (value - 32) * 5/9
85
+ elif to_unit == "Kelvin":
86
+ result = (value - 32) * 5/9 + 273.15
87
+ else:
88
+ result = value
89
+ elif from_unit == "Kelvin":
90
+ if to_unit == "Celsius":
91
+ result = value - 273.15
92
+ elif to_unit == "Fahrenheit":
93
+ result = (value - 273.15) * 9/5 + 32
94
+ else:
95
+ result = value
96
+ st.success(f"Converted Value: **{result:.2f} {to_unit}**")
97
+
98
+ # File Converter
99
+ elif conversion_type == "File Converter":
100
+ st.header("File Converter")
101
+ file_type = st.selectbox("Select File Type", ["PDF to Word", "Image to PDF"])
102
+
103
+ if file_type == "PDF to Word":
104
+ uploaded_file = st.file_uploader("Upload a PDF file", type="pdf")
105
+ if uploaded_file is not None:
106
+ if st.button("Convert to Word"):
107
+ reader = PdfReader(uploaded_file)
108
+ document = Document()
109
+ for page in reader.pages:
110
+ text = page.extract_text()
111
+ document.add_paragraph(text)
112
+ word_file = "converted.docx"
113
+ document.save(word_file)
114
+ st.success("Conversion successful!")
115
+ st.download_button("Download Word File", word_file, file_name="converted.docx")
116
+
117
+ elif file_type == "Image to PDF":
118
+ uploaded_file = st.file_uploader("Upload an Image file", type=["jpg", "jpeg", "png"])
119
+ if uploaded_file is not None:
120
+ if st.button("Convert to PDF"):
121
+ images = convert_from_bytes(uploaded_file.read())
122
+ pdf_file = "converted.pdf"
123
+ images[0].save(pdf_file, "PDF")
124
+ st.success("Conversion successful!")
125
+ st.download_button("Download PDF File", pdf_file, file_name="converted.pdf")
126
+
127
+ # Image Converter
128
+ elif conversion_type == "Image Converter":
129
+ st.header("Image Converter")
130
+ image_type = st.selectbox("Select Conversion Type", ["JPG to PNG", "PNG to JPG"])
131
+
132
+ uploaded_file = st.file_uploader("Upload an Image file", type=["jpg", "jpeg", "png"])
133
+ if uploaded_file is not None:
134
+ if st.button("Convert"):
135
+ image = Image.open(uploaded_file)
136
+ if image_type == "JPG to PNG":
137
+ output_format = "PNG"
138
+ output_file = "converted.png"
139
+ elif image_type == "PNG to JPG":
140
+ output_format = "JPEG"
141
+ output_file = "converted.jpg"
142
+
143
+ # Save the converted image
144
+ image.save(output_file, output_format)
145
+ st.success("Conversion successful!")
146
+ st.download_button(f"Download {output_format} File", output_file, file_name=output_file)
147
+
148
+ # Image Resizer
149
+ elif conversion_type == "Image Resizer":
150
+ st.header("Image Resizer")
151
+ uploaded_file = st.file_uploader("Upload an Image file", type=["jpg", "jpeg", "png"])
152
+ if uploaded_file is not None:
153
+ width = st.number_input("Enter Width", min_value=1, value=500)
154
+ height = st.number_input("Enter Height", min_value=1, value=500)
155
+
156
+ if st.button("Resize"):
157
+ image = Image.open(uploaded_file)
158
+ resized_image = image.resize((width, height))
159
+ resized_file = "resized_image.png"
160
+ resized_image.save(resized_file, "PNG")
161
+ st.success("Resizing successful!")
162
+ st.download_button("Download Resized Image", resized_file, file_name=resized_file)
163
+
164
+ # Date and Time Converter
165
+ elif conversion_type == "Date and Time Converter":
166
+ st.header("Date and Time Converter")
167
+ date_input = st.date_input("Select a Date")
168
+ time_input = st.time_input("Select a Time")
169
+ datetime_obj = datetime.combine(date_input, time_input)
170
+
171
+ st.write("Converted Date and Time:")
172
+ st.write(f"ISO Format: **{datetime_obj.isoformat()}**")
173
+ st.write(f"Timestamp: **{datetime_obj.timestamp()}**")
174
+
175
+ # Number System Converter
176
+ elif conversion_type == "Number System Converter":
177
+ st.header("Number System Converter")
178
+ number = st.number_input("Enter a Number", min_value=0)
179
+ number_system = st.selectbox("Convert to", ["Binary", "Hexadecimal", "Octal"])
180
+
181
+ if st.button("Convert"):
182
+ if number_system == "Binary":
183
+ result = bin(number)
184
+ elif number_system == "Hexadecimal":
185
+ result = hex(number)
186
+ elif number_system == "Octal":
187
+ result = oct(number)
188
+ st.success(f"Converted Value: **{result}**")
189
+
190
+ # Footer
191
+ st.markdown("---")
192
+ st.write("© 2023 Everything Converter. All rights reserved.")