Spaces:
Sleeping
Sleeping
| import os | |
| import requests | |
| import gradio as gr | |
| api_key = os.environ.get('MY_API_KEY') | |
| def encrypt_decrypt(input_text, key, operation, method): | |
| # Define the API endpoint | |
| api_url = "https://api.nvcf.nvidia.com/v2/nvcf/pexec/functions/347fa3f3-d675-432c-b844-669ef8ee53df" | |
| headers = { | |
| 'Authorization': f'Bearer {api_key}', | |
| 'Content-Type': 'application/json' | |
| } | |
| # Construct the message for the AI | |
| message = f"{operation.lower()} this message: '{input_text}' with key {key} using {method} method" | |
| data = { | |
| "messages": [ | |
| {"content": message, "role": "user"} | |
| ], | |
| "stream": False | |
| } | |
| # Make the API request | |
| response = requests.post(api_url, headers=headers, json=data) | |
| # Check the response status | |
| if response.status_code == 200: | |
| response_data = response.json() | |
| if 'choices' in response_data and len(response_data['choices']) > 0: | |
| content = response_data['choices'][0].get('message', {}).get('content', '') | |
| return content | |
| else: | |
| return "No content found in response" | |
| else: | |
| return f"Error: {response.text}" | |
| # Create the Gradio interface | |
| interface = gr.Interface( | |
| fn=encrypt_decrypt, | |
| inputs=[ | |
| gr.Textbox(label="Message", placeholder="Enter your message here..."), | |
| gr.Textbox(label="Key", placeholder="Enter your key here..."), | |
| gr.Radio(choices=["Encrypt", "Decrypt"], label="Operation"), | |
| gr.Dropdown(choices=["AES", "Vigenere Cipher", "Caesar Cipher"], label="Encryption Method") | |
| ], | |
| outputs=gr.Textbox(label="Result") | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| interface.launch() |