File size: 1,111 Bytes
258a502
 
3af81f3
258a502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3af81f3
 
 
 
 
 
 
258a502
3af81f3
258a502
 
 
 
3af81f3
258a502
 
3af81f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
import gradio as gr
import tempfile

def update_swagger(swagger_content):
    try:
        # Load existing swagger.json content
        swagger_data = json.loads(swagger_content)
        
        # Update the info object
        swagger_data['info'] = {
            "title": "My API",
            "version": "1.0.0",
            "description": "Your API description"
        }
        
        # Convert back to JSON string
        updated_swagger = json.dumps(swagger_data, indent=2)
        
        # Save to a temporary file for download
        with tempfile.NamedTemporaryFile(delete=False, suffix=".json") as temp_file:
            temp_file.write(updated_swagger.encode("utf-8"))
            temp_file_path = temp_file.name
        
        return updated_swagger, temp_file_path
    except Exception as e:
        return f"Error updating swagger.json: {e}", None

demo = gr.Interface(
    fn=update_swagger,
    inputs=gr.Textbox(lines=20, label="Input Swagger JSON"),
    outputs=[gr.Textbox(lines=20, label="Updated Swagger JSON"), gr.File(label="Download Updated JSON")]
)

demo.launch()