| from langchain_ollama import ChatOllama | |
| from langchain_core.prompts import ChatPromptTemplate | |
| import gradio as gr | |
| from langchain_groq import ChatGroq | |
| import os | |
| groq_api_key = os.environ.get("GROQ_API_KEY") | |
| llm = ChatGroq( | |
| model="mixtral-8x7b-32768", | |
| temperature=0.7, | |
| api_key=groq_api_key, | |
| verbose = False | |
| ) | |
| prompt = ChatPromptTemplate.from_messages( | |
| [ | |
| ("system","Generate a list of synonyms for the following word, only give 5 words with examples."), | |
| ("human","{input}") | |
| ] | |
| ) | |
| def synonyms(text): | |
| response = chain.invoke({"input": text}) | |
| return response.content | |
| chain = prompt | llm | |
| demo = gr.Interface( | |
| fn = synonyms, | |
| inputs = ["text"], | |
| outputs = ["text"], | |
| title = "Synonym Generator", | |
| description = "Generate a list of synonyms for the following word" | |
| ) | |
| demo.launch() |