hashirehtisham commited on
Commit
d135f83
·
verified ·
1 Parent(s): 1aaa8c4

Delete txt.txt

Browse files
Files changed (1) hide show
  1. txt.txt +0 -99
txt.txt DELETED
@@ -1,99 +0,0 @@
1
- import streamlit as st
2
- from ai71 import AI71
3
- import os
4
-
5
- # Initialize AI71 client
6
- AI71_API_KEY = os.getenv("AI71_API_KEY") # Access the secret from environment variables
7
- client = AI71(AI71_API_KEY)
8
-
9
- # Define your functions and Streamlit UI
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
- for val in history:
20
- if val[0]:
21
- messages.append({"role": "user", "content": val[0]})
22
- if val[1]:
23
- messages.append({"role": "assistant", "content": val[1]})
24
-
25
- messages.append({"role": "user", "content": message})
26
-
27
- response = ""
28
-
29
- for chunk in client.chat.completions.create(
30
- model="tiiuae/falcon-180B-chat",
31
- messages=messages,
32
- max_tokens=max_tokens,
33
- temperature=temperature,
34
- top_p=top_p,
35
- stream=True,
36
- ):
37
- delta_content = chunk.choices[0].delta.content
38
- if delta_content:
39
- response += delta_content
40
-
41
- return response
42
-
43
- def send_message():
44
- message = st.session_state["new_message"]
45
- if message:
46
- response = respond(
47
- message=message,
48
- history=st.session_state.history,
49
- system_message=st.session_state.system_message,
50
- max_tokens=st.session_state.max_tokens,
51
- temperature=st.session_state.temperature,
52
- top_p=st.session_state.top_p,
53
- )
54
- st.session_state.history.append((message, response))
55
- st.session_state["new_message"] = ""
56
-
57
- # Streamlit UI
58
- st.title("AI Lawyer Chatbot")
59
- st.write("Welcome to your legal assistant. How can I assist you with your legal questions today?")
60
- st.markdown("<p style='color:blue;'>Developed by Hashir Ehtisham</p>", unsafe_allow_html=True)
61
-
62
- # Add description to sidebar
63
- st.sidebar.markdown("""
64
- ### AI Lawyer Chatbot
65
- Welcome to your AI Lawyer Chatbot, a cutting-edge tool designed to assist you with legal questions and provide insightful legal advice. Developed by Hashir Ehtisham, this application leverages advanced AI technology to offer accurate and relevant legal information.
66
-
67
- #### Features:
68
- - **Interactive Chat**: Engage in real-time conversations with the chatbot, designed to simulate interactions with a knowledgeable legal expert.
69
- - **Customizable Settings**: Adjust the behavior of the AI with settings for max tokens, temperature, and top-p (nucleus sampling) to fine-tune responses according to your needs.
70
- - **Chat History**: Review previous interactions with the chatbot directly in the app, keeping track of your legal inquiries and the AI's responses.
71
-
72
- #### How It Works:
73
- - **System Message**: The chatbot operates with a predefined system message that sets the context for its responses, ensuring it provides legal advice and information accurately.
74
- - **Real-Time Interaction**: As you input your messages, the AI processes them and generates responses based on the ongoing conversation history and the selected settings.
75
- - **Adaptive Response**: The chatbot's response can be adjusted by changing parameters such as the number of tokens generated, the randomness of the responses (temperature), and the focus on the most likely outcomes (top-p).
76
-
77
- This tool is designed to enhance your understanding of legal matters and provide immediate support for your legal inquiries. Enjoy a seamless and informative interaction with your AI-powered legal assistant!
78
- """)
79
-
80
- # Set default system message directly
81
- if 'system_message' not in st.session_state:
82
- st.session_state.system_message = "You are a knowledgeable AI lawyer providing legal advice and information."
83
-
84
- with st.expander("Settings"):
85
- max_tokens_options = [64, 128, 256, 512, 1024, 2048]
86
- temperature_options = [0.1, 0.3, 0.5, 0.7, 1.0, 1.5, 2.0, 3.0, 4.0]
87
- top_p_options = [0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9, 0.95, 1.0]
88
-
89
- max_tokens = st.selectbox("Max new tokens", options=max_tokens_options, index=max_tokens_options.index(512), key="max_tokens")
90
- temperature = st.selectbox("Temperature", options=temperature_options, index=temperature_options.index(0.7), key="temperature")
91
- top_p = st.selectbox("Top-p (nucleus sampling)", options=top_p_options, index=top_p_options.index(0.95), key="top_p")
92
-
93
- if 'history' not in st.session_state:
94
- st.session_state.history = []
95
-
96
- # Display chat history above the message input
97
- st.text_area("Chat History", value="\n\n".join([f"User: {h[0]}\n\nAI Lawyer: {h[1]}" for h in st.session_state.history]), height=400, key="chat_history")
98
-
99
- message = st.text_input("Your message", key="new_message", on_change=send_message)