|
|
import gradio as gr |
|
|
from sentence_transformers import SentenceTransformer, util |
|
|
import openai |
|
|
import os |
|
|
|
|
|
os.environ["TOKENIZERS_PARALLELISM"] = "false" |
|
|
|
|
|
|
|
|
filename = "output_topic_details.txt" |
|
|
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." |
|
|
|
|
|
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 |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
theme = gr.themes.Monochrome( |
|
|
primary_hue="blue", |
|
|
secondary_hue="gray", |
|
|
).set( |
|
|
background_fill_primary='*primary_200', |
|
|
background_fill_primary_dark='*primary_200', |
|
|
|
|
|
with gr.Blocks(theme=theme) as demo: |
|
|
theme='gstaff/xkcd' |
|
|
|
|
|
gr.Markdown(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) |
|
|
|
|
|
|
|
|
|
|
|
demo.launch(share=True) |
|
|
|