andreska commited on
Commit
37e2bea
·
verified ·
1 Parent(s): e0b1e2b

Try get input data

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -7,21 +7,19 @@ def answer_question(project_data, question):
7
  return answer
8
 
9
  with gr.Blocks() as demo: # Create a Blocks context
10
- iface = gr.Interface(
11
- fn=answer_question,
12
- inputs=["text", "text"],
13
- outputs="text"
14
- )
15
 
16
- def listen_for_messages():
17
- def handle_message(event):
18
- if event.data.type == 'initial_input':
19
- iface.update(inputs=[event.data.project_data, event.data.question])
20
- else:
21
- iface.update(inputs=['test1', 'test2'])
22
 
23
- window.addEventListener('message', handle_message)
24
 
25
- iface.load(listen_for_messages)
26
-
27
- demo.launch()
 
 
 
7
  return answer
8
 
9
  with gr.Blocks() as demo: # Create a Blocks context
10
+ project_data = gr.Textbox(label="Project Data", lines=2, value=state.context)
11
+ output = gr.Textbox(label="Output")
 
 
 
12
 
13
+ def on_message(event):
14
+ # Update the textbox value based on the received message
15
+ state.context = event.data
16
+ iface.set_value(project_data, value=state.context)
17
+ iface.set_value(output, value=state.context)
 
18
 
19
+ iface.js_code("window.addEventListener("message", on_message);)
20
 
21
+ iface.launch(
22
+ server_name="0.0.0.0", # Allow external connections
23
+ share=True, # Create public URL
24
+ allowed_paths=["*"], #Allow CORS
25
+ )