durjoy2 commited on
Commit
878fb0a
·
verified ·
1 Parent(s): 48b3d7e

Upload app2.py

Browse files
Files changed (1) hide show
  1. app2.py +53 -0
app2.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms import HuggingFaceEndpoint
2
+ import os
3
+ from langchain.chains import LLMChain
4
+ from langchain.prompts import PromptTemplate
5
+ import streamlit as st
6
+
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+
12
+ # def qabot(question):
13
+ # llm_hugginface = HuggingFaceEndpoint(repo_id='google/flan-t5-large',token=os.getenv("HUGGINGFACEHUB_API_TOKEN"),temperature=0.5,max_length=128)
14
+ # result= llm_hugginface("Can you write me the capital of {question}")
15
+ # return result
16
+
17
+ # ans =qabot("india")
18
+ # print(ans)
19
+
20
+ # question = "Who won the FIFA World Cup in the year 1994? "
21
+ def qabot(question):
22
+ template = """Question: {question}
23
+
24
+ Answer: Let's think step by step."""
25
+
26
+ prompt = PromptTemplate.from_template(template)
27
+
28
+ repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
29
+
30
+ llm = HuggingFaceEndpoint(
31
+ repo_id=repo_id, max_length=128, temperature=0.5, token=os.getenv('HUGGINGFACEHUB_API_TOKEN')
32
+ )
33
+ llm_chain = LLMChain(prompt=prompt, llm=llm)
34
+ result =llm_chain.run(question)
35
+ return result
36
+
37
+ # print(qabot("Who won the FIFA World Cup in the year 1994? "))
38
+
39
+
40
+
41
+ st.header("Langchain Application")
42
+
43
+ input=st.text_input("Input: ",key="input")
44
+ response=qabot(input)
45
+
46
+ submit=st.button("Ask the question")
47
+
48
+ ## If ask button is clicked
49
+
50
+ if submit:
51
+ st.subheader("The Response is")
52
+ st.write(response)
53
+