bestroi commited on
Commit
371ffd7
·
verified ·
1 Parent(s): ffe03e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -67
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
- with gr.TabItem("AI Answers (Groq API)"):
553
- gr.Markdown("Ask questions about the dataset and get AI-generated answers using the Groq API with the deepseek-r1-distill-llama-70b model.")
554
-
555
- with gr.Row():
556
- with gr.Column():
557
- # API key is now hardcoded in the code
558
-
559
- ai_city_dropdown = gr.Dropdown(
560
- choices=city_names,
561
- value=city_names[0] if city_names else None,
562
- label="Select City"
563
- )
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
-
571
- max_sources_slider = gr.Slider(
572
- minimum=1,
573
- maximum=10,
574
- value=3,
575
- step=1,
576
- label="Maximum Number of Sources to Consider",
577
- info="Higher values may provide more comprehensive answers but will take longer"
578
- )
579
-
580
- temperature_slider = gr.Slider(
581
- minimum=0.0,
582
- maximum=1.0,
583
- value=0.3,
584
- step=0.1,
585
- label="Temperature",
586
- info="Lower values create more focused answers, higher values create more creative ones"
587
- )
588
-
589
- generate_button = gr.Button("Generate Answer")
590
-
591
- with gr.Column():
592
- answer_output = gr.HTML(
593
- label="AI-Generated Answer",
594
- value="",
595
- elem_classes=["results-output"]
596
- )
597
-
598
- def on_generate_answer(city, question, max_sources, api_key, temperature):
599
- if not question or question.strip() == "":
600
- return "Please enter a question to generate an answer."
601
-
602
- # Get the Groq API key from environment variable
603
- groq_api_key = os.environ.get("GROQ_API")
604
-
605
- if not groq_api_key:
606
- return "Error: GROQ_API environment variable not set. Please set your Groq API key in the environment."
607
-
608
- try:
609
- # Use the API key string (not a Groq client object)
610
- return generate_answer_with_groq(city, question, max_sources, groq_api_key, temperature)
611
- except Exception as e:
612
- return f"Error: {str(e)}"
613
-
614
- generate_button.click(
615
- fn=on_generate_answer,
616
- inputs=[ai_city_dropdown, question_input, max_sources_slider, gr.Textbox(visible=False), temperature_slider],
617
- outputs=answer_output
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("""