HareemFatima commited on
Commit
ccc0cf2
·
verified ·
1 Parent(s): eef1762

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from langchain_openai import ChatOpenAI
3
+ from langchain_core.prompts import ChatPromptTemplate
4
+ from langchain_core.output_parsers import StrOutputParser
5
+ from langchain_community.llms import Ollama
6
+ import os
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ os.environ["LANGCHAIN_TRACING_V2"] = "true"
12
+ os.environ["LANGCHAIN_API_KEY"] = os.getenv("LANGCHAIN_API_KEY")
13
+
14
+ # Prompt Template
15
+ prompt = ChatPromptTemplate.from_messages(
16
+ [
17
+ ("system", "You are a helpful assistant. Please respond to the user queries"),
18
+ ("user", "Question:{question}")
19
+ ]
20
+ )
21
+
22
+ # ollama LLama2 LLm
23
+ llm = Ollama(model="llama2")
24
+ output_parser = StrOutputParser()
25
+ chain = prompt | llm | output_parser
26
+
27
+ def chatbot_response(input_text):
28
+ if input_text:
29
+ return chain.invoke({"question": input_text})
30
+ return "Please enter a question."
31
+
32
+ # Gradio Interface
33
+ gr.Interface(fn=chatbot_response, inputs="text", outputs="text", title="Langchain Demo With LLAMA2 API").launch()