Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| from langchain_groq import ChatGroq | |
| from langchain_core.prompts import ChatPromptTemplate | |
| # ------------------------------- | |
| # SYSTEM PROMPT | |
| # ------------------------------- | |
| ai_subhash = """ | |
| You are Subhash AI, a smart and friendly AI Mentor for engineering students. | |
| Explain concepts clearly and step by step in simple words. | |
| Be friendly, motivating, and patient. | |
| After every explanation, ask a small follow-up question. | |
| """ | |
| # ------------------------------- | |
| # LOAD API KEY | |
| # ------------------------------- | |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") | |
| # ------------------------------- | |
| # CREATE MODEL | |
| # ------------------------------- | |
| llm = ChatGroq( | |
| model_name="openai/gpt-oss-120b", | |
| temperature=0.7, | |
| groq_api_key=GROQ_API_KEY | |
| ) | |
| prompt = ChatPromptTemplate.from_messages([ | |
| ("system", ai_subhash), | |
| ("human", "{user_input}") | |
| ]) | |
| chain = prompt | llm | |
| # ------------------------------- | |
| # CHAT FUNCTION | |
| # ------------------------------- | |
| def predict(message, history): | |
| response = chain.invoke({"user_input": message}) | |
| return response.content | |
| # ------------------------------- | |
| # UI | |
| # ------------------------------- | |
| gr.ChatInterface( | |
| fn=predict, | |
| title="Subhash AI – Engineering Mentor", | |
| description="Ask questions about CS, coding, exams, and projects." | |
| ).launch() | |