Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import json # Required for parsing nested JSON | |
| # Function to call your API | |
| def call_jira_api(jira_ticket_header): | |
| try: | |
| # Your API endpoint | |
| api_url = "https://znwkjn2kig.execute-api.us-east-1.amazonaws.com/dev" | |
| # Request payload | |
| payload = {"jira_ticket_header": jira_ticket_header} | |
| # Make the API call | |
| response = requests.post(api_url, json=payload) | |
| # Handle response | |
| if response.status_code == 200: | |
| # Parse the API response | |
| data = response.json() | |
| # Parse the nested JSON in the "body" field | |
| body = json.loads(data.get("body", "{}")) | |
| # Extract the description field | |
| description = body.get("description", "No description found.") | |
| # Return description as plain text | |
| return description | |
| else: | |
| return f"Error {response.status_code}: {response.text}" | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=call_jira_api, # Function to call | |
| inputs=gr.Textbox(label="Jira Ticket Header"), # Input field | |
| outputs=gr.Textbox(label="Generated Description"), # Plain text output | |
| title="Jira Description Generator", | |
| description="Enter the Jira ticket header to generate the description.", | |
| allow_flagging="never" # Disable flagging (removes the Flag button) | |
| ) | |
| # Launch the app | |
| iface.launch() | |