app.py:
"
import os
import gradio as gr
from langchain_groq import ChatGroq # Changed to Groq
from langchain import LLMChain, PromptTemplate
from langchain.memory import ConversationBufferMemory
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "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
Ye mila")
template = """You are a helpful AI and very experienced and you are from India
{chat_history}
User: {user_message}
Chatbot:"""
prompt = PromptTemplate(
input_variables=["chat_history", "user_message"],
template=template
)
memory = ConversationBufferMemory(memory_key="chat_history")
llm = ChatGroq(
temperature=0.5,
model_name="llama3-70b-8192", # Free powerful model
api_key=GROQ_API_KEY # Works without key for basic usage
)
llm_chain = LLMChain(
llm=llm,
prompt=prompt,
verbose=True,
memory=memory,
)
def get_text_response(user_message, history):
response = llm_chain.predict(user_message=user_message)
return response
demo = gr.ChatInterface(
get_text_response,
examples=["How are you doing?", "What are your interests?", "Which places do you like to visit?"],
title="Prabath"
)
if name == "main":
demo.launch(debug=True)
"
requirments.txt:
"
gradio>=4.0
langchain-community==0.2.0
langchain-core==0.2.0
huggingface_hub
langchain-groq
"