Spaces:
Sleeping
Sleeping
File size: 1,701 Bytes
decee39 4d82fc7 decee39 db7a299 01643ee 4d82fc7 decee39 4d82fc7 01643ee db7a299 1fc4ec9 4d82fc7 1fc4ec9 4d82fc7 0fa7a9d 4d82fc7 01643ee db7a299 01643ee 4d82fc7 |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
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() |