Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import random | |
| from huggingface_hub import InferenceClient | |
| from sentence_transformers import SentenceTransformer | |
| custom_theme = gr.themes.Soft( | |
| primary_hue="blue", | |
| secondary_hue="orange", | |
| neutral_hue="rose", | |
| spacing_size="lg", | |
| radius_size="lg", | |
| text_size="lg", | |
| font=[gr.themes.GoogleFont("Montserrat"), "montserrat"], | |
| font_mono=[gr.themes.GoogleFont("IBM Plex Mono"), "monospace"] | |
| ) | |
| embedding_model = SentenceTransformer("all-MiniLM-L6-v2") | |
| client = InferenceClient("Qwen/Qwen2.5-7B-Instruct") | |
| with open("knowledge.txt", "r", encoding="utf-8") as f: | |
| positive_messages = [line.strip() for line in f if line.strip()] | |
| def tac_chatbot(message, history): | |
| messages = [{"role": "system", "content":"You are a friendly chatbot, who can help Tamil people with their queries about Tamil Association. You can speak tamil if they ask for it in Tamil, and you must address them as nanbi, or nanba(meaning friend). If it's not in the database then you must give them this contact: (https://tamilcolorado.org/). "}] | |
| if history: | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat_completion( | |
| messages, | |
| max_tokens = 2100 | |
| ) | |
| return response.choices[0].message.content.strip() | |
| tac = gr.ChatInterface( | |
| tac_chatbot, | |
| title="Tamil Association of Colorado", | |
| description="Hello Nanba,", | |
| textbox=gr.Textbox(placeholder="Ask Me Anything..."), | |
| examples=[ | |
| "How to get membership?", | |
| "Who is the current president?", | |
| "What is the history of TAC?" | |
| ] | |
| ) | |
| with gr.Blocks(theme=custom_theme) as demo: | |
| gr.Image(value="logo.png", show_label=False, elem_id="top-image") | |
| gr.Markdown(""" | |
| <div style="text-align:center"> | |
| <h1 class="glow">Hi, I'm TAC Bot! </h1> | |
| <p style="font-size:18px; max-width:600px; margin:0 auto; color:#ff69b4;"> | |
| I'm going to help you with any questions you have for us: | |
| </p> | |
| </div> | |
| <style> | |
| .glow { | |
| color: #ff4da6; | |
| text-shadow: | |
| 0 0 5px #ff4da6, | |
| 0 0 10px #ff4da6, | |
| 0 0 20px #ff69b4, | |
| 0 0 40px #ff69b4; | |
| font-size: 52px; | |
| margin-bottom: 10px; | |
| } | |
| "<h1 style='text-align:center'>:mortar_board: College Guidance :mortar_board:</h1> | |
| <p style='text-align:center'>Personalized college recommendations based on your interests.</p> | |
| </style> | |
| """) | |
| gr.TabbedInterface([tac], [ "TAC Information" ]) | |
| demo.launch(debug=True) | |