Spaces:
Runtime error
Runtime error
Temp checkin, to check if state can be updated via API
Browse files
app.py
CHANGED
|
@@ -8,12 +8,12 @@ client = InferenceClient(api_key=api_key)
|
|
| 8 |
# Create shared state for the textbox values
|
| 9 |
class State:
|
| 10 |
def __init__(self):
|
| 11 |
-
self.context = ""
|
| 12 |
-
self.question = ""
|
| 13 |
|
| 14 |
state = State()
|
| 15 |
|
| 16 |
-
def analyze(project_data, question):
|
| 17 |
try:
|
| 18 |
prompt = f"Analyze this project: {project_data}\n\nQuestion: {question}"
|
| 19 |
|
|
@@ -38,12 +38,13 @@ def analyze(project_data, question):
|
|
| 38 |
except Exception as e:
|
| 39 |
print(f"Error details: {str(e)}")
|
| 40 |
yield f"Error occurred: {str(e)}"
|
|
|
|
| 41 |
|
| 42 |
# Function to update textbox values
|
| 43 |
def update_values(context, question):
|
| 44 |
state.context = context
|
| 45 |
state.question = question
|
| 46 |
-
return state.context, state.question
|
| 47 |
|
| 48 |
with gr.Blocks() as iface:
|
| 49 |
# Create the components with the state values
|
|
@@ -55,16 +56,18 @@ with gr.Blocks() as iface:
|
|
| 55 |
analyze_btn = gr.Button("Analyze")
|
| 56 |
|
| 57 |
# Connect the analyze function
|
| 58 |
-
analyze_btn.click(
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
)
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
iface.
|
| 66 |
-
gr.on(triggers=["update_values"], fn=update_values)
|
| 67 |
-
|
| 68 |
|
| 69 |
# Configure for external access
|
| 70 |
iface.launch(
|
|
|
|
| 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"
|
| 12 |
+
self.question = "What does this component do?"
|
| 13 |
|
| 14 |
state = State()
|
| 15 |
|
| 16 |
+
'''def analyze(project_data, question):
|
| 17 |
try:
|
| 18 |
prompt = f"Analyze this project: {project_data}\n\nQuestion: {question}"
|
| 19 |
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
print(f"Error details: {str(e)}")
|
| 40 |
yield f"Error occurred: {str(e)}"
|
| 41 |
+
'''
|
| 42 |
|
| 43 |
# Function to update textbox values
|
| 44 |
def update_values(context, question):
|
| 45 |
state.context = context
|
| 46 |
state.question = question
|
| 47 |
+
#return [state.context, state.question]
|
| 48 |
|
| 49 |
with gr.Blocks() as iface:
|
| 50 |
# Create the components with the state values
|
|
|
|
| 56 |
analyze_btn = gr.Button("Analyze")
|
| 57 |
|
| 58 |
# Connect the analyze function
|
| 59 |
+
#analyze_btn.click(
|
| 60 |
+
# fn=analyze,
|
| 61 |
+
# inputs=[project_data, question],
|
| 62 |
+
# outputs=output
|
| 63 |
+
#)
|
| 64 |
+
update_btn.click(
|
| 65 |
+
fn=update_values,
|
| 66 |
+
inputs=['test1', 'test2']
|
| 67 |
)
|
| 68 |
|
| 69 |
+
# Add API endpoint for updating values
|
| 70 |
+
iface.add_api_route("/update_values", update_values, methods=["POST"])
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Configure for external access
|
| 73 |
iface.launch(
|