Shankarm08 commited on
Commit
0a640b3
·
verified ·
1 Parent(s): a0872c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -2,35 +2,35 @@
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
- from transformers import pipeline
6
 
7
- # Load the Hugging Face model (GPT-2 in this case)
8
- @st.cache_resource
9
- def load_model():
10
- return pipeline("text-generation", model="gpt-4o")
11
 
12
- # Function to return the response from Hugging Face model
 
 
13
  def load_answer(question):
14
- model = load_model()
15
- answer = model(question, max_length=100, num_return_sequences=1)
16
- return answer[0]['generated_text']
 
17
 
18
- # App UI starts here
19
- st.set_page_config(page_title="Hugging Face Demo", page_icon=":robot:")
20
- st.header("Hugging Face Demo")
21
 
22
- # Gets the user input
23
  def get_text():
24
  input_text = st.text_input("You: ", key="input")
25
  return input_text
26
 
27
- user_input = get_text()
 
28
  response = load_answer(user_input)
29
 
30
- submit = st.button('Generate')
31
 
32
- # If generate button is clicked
33
  if submit:
 
34
  st.subheader("Answer:")
35
- st.write(response)
36
 
 
 
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
 
7
+ from langchain.llms import openai
8
+
9
+ #Function to return the response
10
  def load_answer(question):
11
+ llm = OpenAI(model_name="gpt-4-turbo-preview",temperature=0)
12
+ answer=llm(question)
13
+ return answer
14
+
15
 
16
+ #App UI starts here
17
+ st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
18
+ st.header("LangChain Demo")
19
 
20
+ #Gets the user input
21
  def get_text():
22
  input_text = st.text_input("You: ", key="input")
23
  return input_text
24
 
25
+
26
+ user_input=get_text()
27
  response = load_answer(user_input)
28
 
29
+ submit = st.button('Generate')
30
 
31
+ #If generate button is clicked
32
  if submit:
33
+
34
  st.subheader("Answer:")
 
35
 
36
+ st.write(response)