sankar12345 commited on
Commit
aecf595
1 Parent(s): 8b88e5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -27
app.py CHANGED
@@ -1,44 +1,36 @@
1
- #Hello! It seems like you want to import the Streamlit library in Python. Streamlit is a powerful open-source framework used for building web applications with interactive data visualizations and machine learning models. To import Streamlit, you'll need to ensure that you have it installed in your Python environment.
2
- #Once you have Streamlit installed, you can import it into your Python script using the import statement,
3
-
4
  import streamlit as st
5
-
6
- #from langchain_openai import OpenAI
7
  from langchain.llms import HuggingFaceEndpoint
8
 
9
- #When deployed on huggingface spaces, this values has to be passed using Variables & Secrets setting, as shown in the video :)
10
- #import os
11
- #os.environ["OPENAI_API_KEY"] = "sk-PLfFwPq6y24234234234FJ1Uc234234L8hVowXdt"
12
-
13
- #Function to return the response
14
  def load_answer(question):
15
  llm = HuggingFaceEndpoint(
16
- repo_id="mistralai/Mistral-7B-Instruct-v0.2") # Model link : https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2
17
 
18
- answer=llm.invoke(question)
 
 
 
19
  return answer
20
 
21
-
22
- #App UI starts here
23
  st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
24
  st.header("LangChain Demo by Sankar")
25
 
26
- #Gets the user input
27
  def get_text():
28
  input_text = st.text_input("You: ", key="input")
29
  return input_text
30
 
 
31
 
32
- user_input=get_text()
33
- response = load_answer(user_input)
34
-
35
- submit = st.button('Generate')
36
 
37
- # If generate button is clicked and user_input is not empty
38
- if submit and user_input:
39
- response = load_answer(user_input)
40
- st.subheader("Answer:")
41
- st.write(response)
42
- elif submit:
43
- st.subheader("Answer:")
44
- st.write("Please enter a question.")
 
 
 
 
 
1
  import streamlit as st
 
 
2
  from langchain.llms import HuggingFaceEndpoint
3
 
4
+ # Function to return the response
 
 
 
 
5
  def load_answer(question):
6
  llm = HuggingFaceEndpoint(
7
+ repo_id="mistralai/Mistral-7B-Instruct-v0.2") # Model link: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2
8
 
9
+ if question.strip() == "":
10
+ return "Question cannot be empty. Please enter a valid question."
11
+
12
+ answer = llm.invoke(question)
13
  return answer
14
 
15
+ # App UI starts here
 
16
  st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
17
  st.header("LangChain Demo by Sankar")
18
 
19
+ # Gets the user input
20
  def get_text():
21
  input_text = st.text_input("You: ", key="input")
22
  return input_text
23
 
24
+ user_input = get_text()
25
 
26
+ submit = st.button('Generate')
 
 
 
27
 
28
+ # If generate button is clicked
29
+ if submit:
30
+ if user_input.strip() == "":
31
+ st.subheader("Answer:")
32
+ st.write("Question cannot be empty. Please enter a valid question.")
33
+ else:
34
+ response = load_answer(user_input)
35
+ st.subheader("Answer:")
36
+ st.write(response)