Upload 2 files
Browse files- app.py +55 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from langchain_community.llms import HuggingFaceEndpoint
|
4 |
+
from langchain.chains import LLMChain
|
5 |
+
from langchain_core.prompts import PromptTemplate
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
# Setting the API
|
11 |
+
model_Api = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
12 |
+
repo_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
13 |
+
|
14 |
+
def QueryBuilding():
|
15 |
+
Query_template = """Consider yourself as a personalized helper to let farmers know how to handle biogas plant, for the user {query},
|
16 |
+
|
17 |
+
Answer: provide guidance and support to the user in a more detailed, simple and straightforward manner."""
|
18 |
+
return Query_template
|
19 |
+
|
20 |
+
def PromptEngineering():
|
21 |
+
Prompt = PromptTemplate.from_template(QueryBuilding())
|
22 |
+
return Prompt
|
23 |
+
|
24 |
+
def LLM_building():
|
25 |
+
llm_model = HuggingFaceEndpoint(
|
26 |
+
repo_id=repo_id,
|
27 |
+
max_length=128,
|
28 |
+
token=model_Api
|
29 |
+
)
|
30 |
+
return llm_model
|
31 |
+
|
32 |
+
def langchainning():
|
33 |
+
llm_chain = LLMChain(prompt=PromptEngineering(), llm=LLM_building())
|
34 |
+
return llm_chain
|
35 |
+
|
36 |
+
def user_input(user):
|
37 |
+
ans = langchainning().run(user)
|
38 |
+
return ans
|
39 |
+
|
40 |
+
def chat_interface(message, history):
|
41 |
+
response = user_input(message)
|
42 |
+
return response
|
43 |
+
|
44 |
+
iface = gr.ChatInterface(
|
45 |
+
fn=chat_interface,
|
46 |
+
title="Gas Whizz",
|
47 |
+
description="Hello Friend, How can I help you today?",
|
48 |
+
examples=["How does a biogas plant work?", "What are the benefits of biofuel?"],
|
49 |
+
retry_btn=None,
|
50 |
+
undo_btn="Delete Previous",
|
51 |
+
clear_btn="Clear",
|
52 |
+
)
|
53 |
+
|
54 |
+
if __name__ == "__main__":
|
55 |
+
iface.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
langchain
|
3 |
+
langchain-community
|
4 |
+
langchain-core
|
5 |
+
huggingface_hub
|
6 |
+
python-dotenv
|