import gradio as gr from sentence_transformers import SentenceTransformer, util import openai import os os.environ["TOKENIZERS_PARALLELISM"] = "false" # Initialize paths and model identifiers for easy configuration and maintenance filename = "output_topic_details.txt" # Path to the file storing chess-specific details retrieval_model_name = 'output/sentence-transformer-finetuned/' openai.api_key = os.environ["OPENAI_API_KEY"] system_message = "You are a chatbot specialized in providing information the Young Yale Global Scholars program. You will be giving information to be applicants and scholars." # Initial system message to set the behavior of the assistant messages = [{"role": "system", "content": system_message}] Generate a response emphasizing the bot's capability in providing exercise information. """ try: user_message = f"Here's the information on YYGS: {relevant_segment}" # Append user's message to messages list messages.append({"role": "user", "content": user_message}) Process a question, find relevant information, and generate a response. """ if question == "": return "Welcome to Ask YYGS! Ask any question related to the YYGS program and this chatbot should be able to help!" relevant_segment = find_relevant_segment(question, segments) if not relevant_segment: return "Could not find specific information. Please refine your question." welcome_message = """ # ## AskYYGS is an AI-driven assistant for all Young Yale Global Scholar related queries. Created by Alexandra, Loli, Abigail, and Lisa at the 2025 YYGS Hack-A-Thon. """ topics = """ ### Here are some ideas of things you can ask about! - Class Locations - Where to get help - Laundry - Roomate Question Ideas - Things To Do - What the programs mean - Example Lectures - Dining Shifts and the Menu - How to Beat the Heat """ # Setup the Gradio Blocks interface with custom layout components theme = gr.themes.Monochrome( primary_hue="blue", secondary_hue="gray", ).set( background_fill_primary='*primary_200', background_fill_primary_dark='*primary_200', # Setup the Gradio Blocks interface with custom layout components with gr.Blocks(theme=theme) as demo: theme='gstaff/xkcd' #gr.Image("Screenshot 2024-08-01 at 11.03.58 AM.png", show_label = False, show_share_button = False, show_download_button = False, width = 1800, height = 470) gr.Markdown(welcome_message) # Display the formatted welcome message with gr.Row(): with gr.Column(): gr.Markdown(topics) with gr.Row(): with gr.Column(): question = gr.Textbox(label="Your question", placeholder="What do you want to ask about?") answer = gr.Textbox(label="Ask YYGS's Response:", placeholder="askYYGS will respond here...", interactive=False, lines=10) submit_button = gr.Button("Submit") submit_button.click(fn=query_model, inputs=question, outputs=answer) with gr.Row(): with gr.Column(): question = gr.Textbox(label="Your question", placeholder="What do you want to ask about?") answer = gr.Textbox(label="Ask YYGS's Response:", placeholder="askYYGS will respond here...", interactive=False, lines=10) submit_button = gr.Button("Submit") submit_button.click(fn=query_model, inputs=question, outputs=answer) # Launch the Gradio app to allow user interaction demo.launch(share=True)