Spaces:
No application file
No application file
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|