Spaces:
Sleeping
Sleeping
Try fix by Amazon Q
Browse files
app.py
CHANGED
|
@@ -1,39 +1,62 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
|
| 3 |
-
class State:
|
| 4 |
-
def __init__(self):
|
| 5 |
-
self.context = "This Adrega component is designed to answer questions provided by API"
|
| 6 |
-
self.question = "What does this component do?"
|
| 7 |
|
| 8 |
-
state = State()
|
| 9 |
|
| 10 |
-
|
| 11 |
-
window.addEventListener("message", on_message);
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
def update_values(context, question):
|
| 15 |
state.context = context
|
| 16 |
state.question = question
|
| 17 |
return "I have stored the new values"
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
state.context = event.data
|
| 32 |
-
iface.set_value(project_data, value=state.context)
|
| 33 |
-
iface.set_value(output, value=state.context)
|
| 34 |
-
|
| 35 |
-
iface.launch(
|
| 36 |
-
server_name="0.0.0.0", # Allow external connections
|
| 37 |
-
share=True, # Create public URL
|
| 38 |
-
allowed_paths=["*"], #Allow CORS
|
| 39 |
)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
|
| 3 |
+
class State:
|
| 4 |
+
def __init__(self):
|
| 5 |
+
self.context = "This Adrega component is designed to answer questions provided by API"
|
| 6 |
+
self.question = "What does this component do?"
|
| 7 |
|
| 8 |
+
state = State()
|
| 9 |
|
| 10 |
+
def update_values(context, question):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
state.context = context
|
| 12 |
state.question = question
|
| 13 |
return "I have stored the new values"
|
| 14 |
+
|
| 15 |
+
def process_message(message):
|
| 16 |
+
# Handle incoming messages
|
| 17 |
+
state.context = message
|
| 18 |
+
return message
|
| 19 |
+
|
| 20 |
+
# JavaScript for message handling
|
| 21 |
+
js = """
|
| 22 |
+
function on_message(event) {
|
| 23 |
+
if (event.data && event.data.projectData) {
|
| 24 |
+
// Access the gradio elements through window.gradio
|
| 25 |
+
const projectData = event.data.projectData;
|
| 26 |
+
const question = event.data.question;
|
| 27 |
+
|
| 28 |
+
// Update the textboxes
|
| 29 |
+
document.querySelector('#project_data textarea').value = projectData;
|
| 30 |
+
document.querySelector('#output textarea').value = question;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
window.addEventListener('message', on_message);
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
with gr.Blocks(js=js) as demo:
|
| 37 |
+
with gr.Row():
|
| 38 |
+
project_data = gr.Textbox(
|
| 39 |
+
label="Project Data",
|
| 40 |
+
lines=2,
|
| 41 |
+
value=state.context,
|
| 42 |
+
elem_id="project_data"
|
| 43 |
+
)
|
| 44 |
+
output = gr.Textbox(
|
| 45 |
+
label="Output",
|
| 46 |
+
elem_id="output"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Add interface for update_values function
|
| 50 |
+
update_btn = gr.Button("Update Values")
|
| 51 |
+
update_btn.click(
|
| 52 |
+
fn=update_values,
|
| 53 |
+
inputs=[project_data, output],
|
| 54 |
+
outputs=output
|
| 55 |
)
|
| 56 |
+
|
| 57 |
+
# Launch the app
|
| 58 |
+
demo.launch(
|
| 59 |
+
server_name="0.0.0.0",
|
| 60 |
+
share=True,
|
| 61 |
+
allowed_paths=["*"] # Be careful with this in production
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
)
|