jeroenherczeg commited on
Commit
1bf76d8
1 Parent(s): 36b5137
Files changed (3) hide show
  1. README.md +3 -3
  2. app.py +38 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Question Answering System
3
  emoji: 🏆
4
- colorFrom: pink
5
- colorTo: pink
6
  sdk: streamlit
7
  sdk_version: 1.35.0
8
  app_file: app.py
 
1
  ---
2
+ title: Question-Answering System
3
  emoji: 🏆
4
+ colorFrom: purple
5
+ colorTo: purple
6
  sdk: streamlit
7
  sdk_version: 1.35.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ import streamlit as st
3
+
4
+
5
+ st.markdown('''
6
+ Hey there, I wrote a book titled "**:green[Hands-On Retrieval-Augmented Generation]**," which includes this example application. If you\'re interested in exploring more practical applications of Retrieval-Augmented Generation, be sure to [check it out](https://herczeg.be)!
7
+
8
+ [Go to start](https://huggingface.co/spaces/jeroenherczeg/HORAG-LLM) - [Previous](#) - [Next](#) - [Read the book](https://herczeg.be)
9
+ ''')
10
+
11
+ st.header('LLM', divider='rainbow')
12
+
13
+ client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"])
14
+
15
+ if "openai_model" not in st.session_state:
16
+ st.session_state["openai_model"] = "gpt-3.5-turbo"
17
+
18
+ if "messages" not in st.session_state:
19
+ st.session_state.messages = []
20
+
21
+ for message in st.session_state.messages:
22
+ with st.chat_message(message["role"]):
23
+ st.markdown(message["content"])
24
+
25
+ if prompt := st.chat_input("What is up?"):
26
+ st.session_state.messages = []
27
+ st.session_state.messages.append({"role": "user", "content": prompt})
28
+ with st.chat_message("user"):
29
+ st.markdown(prompt)
30
+
31
+ with st.chat_message("assistant"):
32
+ stream = client.chat.completions.create(
33
+ model=st.session_state["openai_model"],
34
+ messages=[{"role": "user", "content": prompt}],
35
+ stream=True,
36
+ )
37
+ response = st.write_stream(stream)
38
+ st.session_state.messages.append({"role": "assistant", "content": response})
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ streamlit