Spaces:
Sleeping
Sleeping
File size: 1,336 Bytes
eeffe18 4339c67 eeffe18 4339c67 eeffe18 4339c67 eeffe18 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 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()
|