-
Notifications
You must be signed in to change notification settings - Fork 373
/
app.py
59 lines (49 loc) · 2.73 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
from g1 import generate_response
import json
def main():
st.set_page_config(page_title="g1 prototype", page_icon="🧠", layout="wide")
st.title("g1: Using Llama-3.1 70b on Groq to create o1-like reasoning chains")
st.markdown("""
This is an early prototype of using prompting to create o1-like reasoning chains to improve output accuracy. It is not perfect and accuracy has yet to be formally evaluated. It is powered by Groq so that the reasoning step is fast!
Open source [repository here](https://github.com/bklieger-groq)
""")
# Text input for user query
user_query = st.text_input("Enter your query:", placeholder="e.g., How many 'R's are in the word strawberry?")
if user_query:
st.write("Generating response...")
# Create empty elements to hold the generated text and total time
response_container = st.empty()
time_container = st.empty()
# Generate and display the response
for steps, total_thinking_time in generate_response(user_query):
with response_container.container():
for i, (title, content, thinking_time) in enumerate(steps):
# Ensure content is a string
if not isinstance(content, str):
content = json.dumps(content)
if title.startswith("Final Answer"):
st.markdown(f"### {title}")
if '```' in content:
parts = content.split('```')
for index, part in enumerate(parts):
if index % 2 == 0:
st.markdown(part)
else:
if '\n' in part:
lang_line, code = part.split('\n', 1)
lang = lang_line.strip()
else:
lang = ''
code = part
st.code(part, language=lang)
else:
st.markdown(content.replace('\n', '<br>'), unsafe_allow_html=True)
else:
with st.expander(title, expanded=True):
st.markdown(content.replace('\n', '<br>'), unsafe_allow_html=True)
# Only show total time when it's available at the end
if total_thinking_time is not None:
time_container.markdown(f"**Total thinking time: {total_thinking_time:.2f} seconds**")
if __name__ == "__main__":
main()