Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -549,73 +549,74 @@ with gr.Blocks(title="Archaeological Query Engine") as app:
|
|
| 549 |
)
|
| 550 |
|
| 551 |
# Add new tab for AI-generated answers using Groq API
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
with
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
|
|
|
| 619 |
|
| 620 |
# Add CSS styling
|
| 621 |
gr.HTML("""
|
|
|
|
| 549 |
)
|
| 550 |
|
| 551 |
# Add new tab for AI-generated answers using Groq API
|
| 552 |
+
with gr.TabItem("AI Answers (Groq API)"):
|
| 553 |
+
gr.Markdown(
|
| 554 |
+
"Ask questions about the dataset and get AI-generated answers using the Groq API "
|
| 555 |
+
"with the deepseek-r1-distill-llama-70b model."
|
| 556 |
+
)
|
| 557 |
+
|
| 558 |
+
with gr.Row():
|
| 559 |
+
with gr.Column():
|
| 560 |
+
ai_city_dropdown = gr.Dropdown(
|
| 561 |
+
choices=city_names,
|
| 562 |
+
value=city_names[0] if city_names else None,
|
| 563 |
+
label="Select City"
|
| 564 |
+
)
|
| 565 |
+
question_input = gr.Textbox(
|
| 566 |
+
label="Ask a Question",
|
| 567 |
+
placeholder="E.g., What was the historical significance of this ancient city?",
|
| 568 |
+
lines=3
|
| 569 |
+
)
|
| 570 |
+
max_sources_slider = gr.Slider(
|
| 571 |
+
minimum=1,
|
| 572 |
+
maximum=10,
|
| 573 |
+
value=3,
|
| 574 |
+
step=1,
|
| 575 |
+
label="Maximum Number of Sources to Consider",
|
| 576 |
+
info="Higher values may provide more comprehensive answers but will take longer"
|
| 577 |
+
)
|
| 578 |
+
temperature_slider = gr.Slider(
|
| 579 |
+
minimum=0.0,
|
| 580 |
+
maximum=1.0,
|
| 581 |
+
value=0.3,
|
| 582 |
+
step=0.1,
|
| 583 |
+
label="Temperature",
|
| 584 |
+
info="Lower values create more focused answers, higher values create more creative ones"
|
| 585 |
+
)
|
| 586 |
+
generate_button = gr.Button("Generate Answer")
|
| 587 |
+
|
| 588 |
+
with gr.Column():
|
| 589 |
+
answer_output = gr.HTML(
|
| 590 |
+
label="AI-Generated Answer",
|
| 591 |
+
value="",
|
| 592 |
+
elem_classes=["results-output"]
|
| 593 |
+
)
|
| 594 |
+
|
| 595 |
+
# Function to handle the Generate Answer button click
|
| 596 |
+
def on_generate_answer(city, question, max_sources, temperature):
|
| 597 |
+
if not question or not question.strip():
|
| 598 |
+
return "Please enter a question to generate an answer."
|
| 599 |
+
groq_api_key = os.environ.get("GROQ_API")
|
| 600 |
+
if not groq_api_key:
|
| 601 |
+
return (
|
| 602 |
+
"Error: GROQ_API environment variable not set. "
|
| 603 |
+
"Please set your Groq API key in the environment."
|
| 604 |
+
)
|
| 605 |
+
try:
|
| 606 |
+
return generate_answer_with_groq(
|
| 607 |
+
city, question, max_sources, groq_api_key, temperature
|
| 608 |
+
)
|
| 609 |
+
except Exception as e:
|
| 610 |
+
return f"Error: {str(e)}"
|
| 611 |
+
|
| 612 |
+
generate_button.click(
|
| 613 |
+
fn=on_generate_answer,
|
| 614 |
+
inputs=[ai_city_dropdown,
|
| 615 |
+
question_input,
|
| 616 |
+
max_sources_slider,
|
| 617 |
+
temperature_slider],
|
| 618 |
+
outputs=answer_output
|
| 619 |
+
)
|
| 620 |
|
| 621 |
# Add CSS styling
|
| 622 |
gr.HTML("""
|