Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,72 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
if __name__ == "__main__":
|
11 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
|
4 |
+
# Function to send a request to Inflection AI API
|
5 |
+
def idea_mirror(input_idea, context=""):
|
6 |
+
try:
|
7 |
+
# API endpoint for Inflection AI (replace with the actual endpoint)
|
8 |
+
api_url = "https://layercake.pubwestus3.inf7ks8.com/external/api/inference"
|
9 |
+
|
10 |
+
# Construct the payload
|
11 |
+
payload = {
|
12 |
+
"context": [
|
13 |
+
{"text": input_idea, "type": "Human"},
|
14 |
+
{"text": context, "type": "Human"} if context else {}
|
15 |
+
],
|
16 |
+
"config": "inflection_3_pi"
|
17 |
+
}
|
18 |
+
|
19 |
+
# Headers with API Key
|
20 |
+
headers = {
|
21 |
+
"Authorization": "Bearer VRks3d8elJWfQ34pVqdkjydFL6S93taWsPCxFIgUWFc",
|
22 |
+
"Content-Type": "application/json"
|
23 |
+
}
|
24 |
+
|
25 |
+
# Send the request
|
26 |
+
response = requests.post(api_url, json=payload, headers=headers)
|
27 |
+
|
28 |
+
# Handle the response
|
29 |
+
if response.status_code == 200:
|
30 |
+
response_data = response.json()
|
31 |
+
result = response_data.get("result", "No se pudo obtener un resultado.")
|
32 |
+
return f"Idea Refinada: {result}"
|
33 |
+
else:
|
34 |
+
return f"Error: {response.status_code}, {response.text}"
|
35 |
+
except Exception as e:
|
36 |
+
return f"Error procesando la idea: {e}"
|
37 |
|
38 |
+
# Gradio Interface
|
39 |
+
with gr.Blocks() as interfaz:
|
40 |
+
gr.Markdown(
|
41 |
+
"""
|
42 |
+
## **Idea Mirror**
|
43 |
+
### Refinamos tus ideas con claridad y empatía.
|
44 |
+
"""
|
45 |
+
)
|
46 |
+
|
47 |
+
with gr.Row():
|
48 |
+
idea_input = gr.Textbox(
|
49 |
+
label="Ingresa tu idea",
|
50 |
+
placeholder="Escribe aquí tu idea principal...",
|
51 |
+
lines=3
|
52 |
+
)
|
53 |
+
context_input = gr.Textbox(
|
54 |
+
label="Contexto (opcional)",
|
55 |
+
placeholder="Añade más detalles sobre tu idea o audiencia...",
|
56 |
+
lines=2
|
57 |
+
)
|
58 |
+
|
59 |
+
output_box = gr.Textbox(
|
60 |
+
label="Resultado",
|
61 |
+
placeholder="Aquí aparecerá tu idea refinada...",
|
62 |
+
lines=6,
|
63 |
+
interactive=False
|
64 |
+
)
|
65 |
+
|
66 |
+
refine_button = gr.Button("Refinar Idea")
|
67 |
|
68 |
+
# Link the refinement function to the button
|
69 |
+
refine_button.click(idea_mirror, inputs=[idea_input, context_input], outputs=output_box)
|
70 |
|
71 |
+
# Launch the Gradio app
|
72 |
+
interfaz.launch()
|
|
|
|