andreska commited on
Commit
4e7bf7a
·
verified ·
1 Parent(s): 7059a3b

Try fix runtime issue

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -5,7 +5,6 @@ from huggingface_hub import InferenceClient
5
  api_key = os.getenv("HF_API_KEY")
6
  client = InferenceClient(api_key=api_key)
7
 
8
- # Create shared state for the textbox values
9
  class State:
10
  def __init__(self):
11
  self.context = "This Adrega component is designed to answer questions provided by API"
@@ -13,30 +12,31 @@ class State:
13
 
14
  state = State()
15
 
16
- # Function to update textbox values
17
- def update_values(context, question):
 
 
 
 
18
  state.context = context
19
  state.question = question
20
- return state.context
21
-
22
  with gr.Blocks() as iface:
23
- project_data = gr.Textbox(label="Project Data", lines=2, value=lambda: state.context)
24
- question = gr.Textbox(label="Question", lines=1, value=lambda: state.question)
25
  output = gr.Textbox(label="Output")
26
-
27
  update_btn = gr.Button("Update")
28
  update_btn.click(
29
  fn=update_values,
30
- inputs=[lambda: project_data, lambda: question],
31
  outputs=output
32
  )
33
 
34
  iface.add_api_route("/update_values", update_values, methods=["POST"])
35
-
36
  iface.launch(
37
  server_name="0.0.0.0", # Allow external connections
38
  share=True, # Create public URL
39
  allowed_paths=["*"], # Allow CORS
40
- )
41
-
42
-
 
5
  api_key = os.getenv("HF_API_KEY")
6
  client = InferenceClient(api_key=api_key)
7
 
 
8
  class State:
9
  def __init__(self):
10
  self.context = "This Adrega component is designed to answer questions provided by API"
 
12
 
13
  state = State()
14
 
15
+ def update_values(update):
16
+ # Access updated values from the Textboxes through `update`
17
+ context = update["project_data"]
18
+ question = update["question"]
19
+
20
+ # Update state and return output (optional)
21
  state.context = context
22
  state.question = question
23
+ return f"Updated context: {context}\nUpdated question: {question}"
24
+
25
  with gr.Blocks() as iface:
26
+ project_data = gr.Textbox(label="Project Data", lines=2, value=state.context)
27
+ question = gr.Textbox(label="Question", lines=1, value=state.question)
28
  output = gr.Textbox(label="Output")
29
+
30
  update_btn = gr.Button("Update")
31
  update_btn.click(
32
  fn=update_values,
33
+ inputs=update, # Access updated values through `update` argument
34
  outputs=output
35
  )
36
 
37
  iface.add_api_route("/update_values", update_values, methods=["POST"])
 
38
  iface.launch(
39
  server_name="0.0.0.0", # Allow external connections
40
  share=True, # Create public URL
41
  allowed_paths=["*"], # Allow CORS
42
+ )