Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -102,24 +102,24 @@ def main():
|
|
| 102 |
st.title("API Spec Uploader and Python Interface Generator")
|
| 103 |
|
| 104 |
# Upload API Spec File
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
# Display API Spec
|
| 125 |
st.subheader("Uploaded API Specification")
|
|
|
|
| 102 |
st.title("API Spec Uploader and Python Interface Generator")
|
| 103 |
|
| 104 |
# Upload API Spec File
|
| 105 |
+
uploaded_file = st.file_uploader("Upload API Spec (JSON, YAML, PDF, DOC)", type=["json", "yaml", "pdf", "docx"])
|
| 106 |
+
|
| 107 |
+
if uploaded_file is not None:
|
| 108 |
+
file_type = uploaded_file.type
|
| 109 |
+
|
| 110 |
+
# Handle different file types
|
| 111 |
+
if file_type == "application/json":
|
| 112 |
+
api_spec_content = uploaded_file.read().decode("utf-8")
|
| 113 |
+
elif file_type == "application/x-yaml":
|
| 114 |
+
api_spec_content = uploaded_file.read().decode("utf-8")
|
| 115 |
+
elif file_type == "application/pdf":
|
| 116 |
+
api_spec_content = read_pdf(uploaded_file)
|
| 117 |
+
elif file_type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" or file_type == "application/octet-stream":
|
| 118 |
+
# Handle docx or unknown types
|
| 119 |
+
api_spec_content = read_docx(uploaded_file)
|
| 120 |
+
else:
|
| 121 |
+
st.error(f"Unsupported file format: {file_type}")
|
| 122 |
+
return
|
| 123 |
|
| 124 |
# Display API Spec
|
| 125 |
st.subheader("Uploaded API Specification")
|