Spaces:
Sleeping
Sleeping
Use Blocks to fix error
Browse files
app.py
CHANGED
|
@@ -1,27 +1,25 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from huggingface_hub import InferenceClient
|
| 4 |
-
|
| 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 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
def listen_for_messages():
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
iface.load(listen_for_messages)
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def answer_question(project_data, question):
|
| 4 |
+
# Process the project_data and question to generate an answer
|
| 5 |
+
# Replace this with your actual logic
|
| 6 |
answer = f"Answer to '{question}' based on '{project_data}': [Your Answer Here]"
|
| 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 |
|
| 21 |
+
window.addEventListener('message', handle_message)
|
| 22 |
|
| 23 |
+
iface.load(listen_for_messages)
|
| 24 |
|
| 25 |
+
demo.launch()
|