Spaces:
Sleeping
Sleeping
Create specific_ui.py
Browse files- specific_ui.py +84 -0
specific_ui.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from tools.general_tools import initialize_perplexity
|
| 3 |
+
from tools.perplexity_tools import (
|
| 4 |
+
get_ai_research_papers,
|
| 5 |
+
summarize_paper,
|
| 6 |
+
get_citation,
|
| 7 |
+
explain_concept,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
def create_specific_ui():
|
| 11 |
+
"""Creates the Specific UI components."""
|
| 12 |
+
with gr.Column() as specific_ui:
|
| 13 |
+
gr.Markdown("# AI Research Assistant (Specific Mode)")
|
| 14 |
+
gr.Markdown("Your AI-powered research companion")
|
| 15 |
+
|
| 16 |
+
with gr.Row():
|
| 17 |
+
gr.Markdown("## Setup Required")
|
| 18 |
+
gr.Markdown("1. Enter Perplexity API key and select a model")
|
| 19 |
+
input_api_key = gr.Textbox(label="Enter your Perplexity API Key:")
|
| 20 |
+
model_dropdown = gr.Dropdown(
|
| 21 |
+
label="Select Perplexity Model",
|
| 22 |
+
choices=[
|
| 23 |
+
"sonar-reasoning-pro",
|
| 24 |
+
"sonar-reasoning",
|
| 25 |
+
"sonar-pro",
|
| 26 |
+
"sonar"
|
| 27 |
+
],
|
| 28 |
+
value="sonar-pro" # Default value
|
| 29 |
+
)
|
| 30 |
+
initialize_button = gr.Button("Initialize Perplexity API")
|
| 31 |
+
|
| 32 |
+
initialization_status = gr.Textbox(label="Initialization Status")
|
| 33 |
+
initialize_button.click(
|
| 34 |
+
fn=initialize_perplexity,
|
| 35 |
+
inputs=[input_api_key, model_dropdown],
|
| 36 |
+
outputs=initialization_status
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
with gr.Row():
|
| 40 |
+
gr.Markdown("## Research Tools")
|
| 41 |
+
input_query = gr.Textbox(label="Search query for AI papers:")
|
| 42 |
+
search_button = gr.Button("Search Papers")
|
| 43 |
+
|
| 44 |
+
search_results = gr.Textbox(label="Search Results")
|
| 45 |
+
search_button.click(
|
| 46 |
+
fn=get_ai_research_papers,
|
| 47 |
+
inputs=[input_query, input_api_key, model_dropdown],
|
| 48 |
+
outputs=search_results
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
input_paper_title = gr.Textbox(label="Paper title to summarize:")
|
| 53 |
+
summarize_button = gr.Button("Summarize Paper")
|
| 54 |
+
|
| 55 |
+
paper_summary = gr.Textbox(label="Paper Summary")
|
| 56 |
+
summarize_button.click(
|
| 57 |
+
fn=summarize_paper,
|
| 58 |
+
inputs=[input_paper_title, input_api_key, model_dropdown],
|
| 59 |
+
outputs=paper_summary
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
with gr.Row():
|
| 63 |
+
input_citation_title = gr.Textbox(label="Paper title to cite:")
|
| 64 |
+
citation_button = gr.Button("Generate Citation")
|
| 65 |
+
|
| 66 |
+
citation_output = gr.Textbox(label="Citation")
|
| 67 |
+
citation_button.click(
|
| 68 |
+
fn=get_citation,
|
| 69 |
+
inputs=[input_citation_title, input_api_key, model_dropdown],
|
| 70 |
+
outputs=citation_output
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
with gr.Row():
|
| 74 |
+
input_concept = gr.Textbox(label="Concept to explain:")
|
| 75 |
+
explain_button = gr.Button("Explain Concept")
|
| 76 |
+
|
| 77 |
+
explanation_output = gr.Textbox(label="Explanation")
|
| 78 |
+
explain_button.click(
|
| 79 |
+
fn=explain_concept,
|
| 80 |
+
inputs=[input_concept, input_api_key, model_dropdown],
|
| 81 |
+
outputs=explanation_output
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
return specific_ui
|