Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
# Function to send a request to Inflection AI API | |
def idea_mirror(input_idea, context=""): | |
try: | |
# API endpoint for Inflection AI (replace with the actual endpoint) | |
api_url = "https://layercake.pubwestus3.inf7ks8.com/external/api/inference" | |
# Construct the payload | |
payload = { | |
"context": [ | |
{"text": input_idea, "type": "Human"}, | |
{"text": context, "type": "Human"} if context else {} | |
], | |
"config": "inflection_3_pi" | |
} | |
# Headers with API Key | |
headers = { | |
"Authorization": "Bearer VRks3d8elJWfQ34pVqdkjydFL6S93taWsPCxFIgUWFc", | |
"Content-Type": "application/json" | |
} | |
# Send the request | |
response = requests.post(api_url, json=payload, headers=headers) | |
# Handle the response | |
if response.status_code == 200: | |
response_data = response.json() | |
result = response_data.get("result", "No se pudo obtener un resultado.") | |
return f"Idea Refinada: {result}" | |
else: | |
return f"Error: {response.status_code}, {response.text}" | |
except Exception as e: | |
return f"Error procesando la idea: {e}" | |
# Gradio Interface | |
with gr.Blocks() as interfaz: | |
gr.Markdown( | |
""" | |
## **Idea Mirror** | |
### Refinamos tus ideas con claridad y empatía. | |
""" | |
) | |
with gr.Row(): | |
idea_input = gr.Textbox( | |
label="Ingresa tu idea", | |
placeholder="Escribe aquí tu idea principal...", | |
lines=3 | |
) | |
context_input = gr.Textbox( | |
label="Contexto (opcional)", | |
placeholder="Añade más detalles sobre tu idea o audiencia...", | |
lines=2 | |
) | |
output_box = gr.Textbox( | |
label="Resultado", | |
placeholder="Aquí aparecerá tu idea refinada...", | |
lines=6, | |
interactive=False | |
) | |
refine_button = gr.Button("Refinar Idea") | |
# Link the refinement function to the button | |
refine_button.click(idea_mirror, inputs=[idea_input, context_input], outputs=output_box) | |
# Launch the Gradio app | |
interfaz.launch() | |