Spaces:
Sleeping
Sleeping
Try create app with initial state
Browse files
app.py
CHANGED
|
@@ -5,44 +5,14 @@ from huggingface_hub import InferenceClient
|
|
| 5 |
api_key = os.getenv("HF_API_KEY")
|
| 6 |
client = InferenceClient(api_key=api_key)
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
self.question = "What does this component do?"
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
def update_values(project_data, question):
|
| 17 |
-
# Access updated values from the Textboxes through `update`
|
| 18 |
-
context = project_data
|
| 19 |
-
question = question
|
| 20 |
-
|
| 21 |
-
# Update state and return output (optional)
|
| 22 |
-
state.context = context
|
| 23 |
-
state.question = question
|
| 24 |
-
return f"Updated context: {context}\nUpdated question: {question}"
|
| 25 |
-
|
| 26 |
-
with gr.Blocks() as iface:
|
| 27 |
-
project_data = gr.Textbox(label="Project Data", lines=2, value=state.context)
|
| 28 |
-
question = gr.Textbox(label="Question", lines=1, value=state.question)
|
| 29 |
-
output = gr.Textbox(label="Output")
|
| 30 |
-
|
| 31 |
-
update_btn = gr.Button("Update")
|
| 32 |
-
update_btn.click(
|
| 33 |
-
fn=update_values,
|
| 34 |
-
inputs=[project_data, question],
|
| 35 |
-
outputs=output
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
iface.load(lambda: window.addEventListener('message', (event) => {
|
| 39 |
-
if (event.data.type === 'initial_input') {
|
| 40 |
-
iface.update(inputs=[event.data.project_data, event.data.question])
|
| 41 |
-
}
|
| 42 |
-
}))
|
| 43 |
-
|
| 44 |
-
iface.launch(
|
| 45 |
-
server_name="0.0.0.0", # Allow external connections
|
| 46 |
-
share=True, # Create public URL
|
| 47 |
-
allowed_paths=["*"], # Allow CORS
|
| 48 |
-
)
|
|
|
|
| 5 |
api_key = os.getenv("HF_API_KEY")
|
| 6 |
client = InferenceClient(api_key=api_key)
|
| 7 |
|
| 8 |
+
def answer_question(project_data, question):
|
| 9 |
+
answer = f"Answer to '{question}' based on '{project_data}': [Your Answer Here]"
|
| 10 |
+
return answer
|
|
|
|
| 11 |
|
| 12 |
+
iface = gr.Interface(
|
| 13 |
+
fn=answer_question,
|
| 14 |
+
inputs=["text", "text"],
|
| 15 |
+
outputs="text"
|
| 16 |
+
)
|
| 17 |
|
| 18 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|