Spaces:
Sleeping
Sleeping
Akshayram1
commited on
Commit
•
73edfbf
1
Parent(s):
dde818b
Update app.py
Browse files
app.py
CHANGED
@@ -15,113 +15,113 @@ chat = None
|
|
15 |
|
16 |
# Generation configuration and safety settings
|
17 |
generation_config = {
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
}
|
23 |
|
24 |
safety_settings = [
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
]
|
42 |
|
43 |
# Function to handle text summary requests
|
44 |
def text_summary(text, isNew=False):
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
|
126 |
# Streamlit UI
|
127 |
st.title("Financial Summary Chatbot")
|
@@ -132,9 +132,9 @@ chat_input = st.text_area("Type a message:", "")
|
|
132 |
|
133 |
# Button to submit the text
|
134 |
if st.button("Send"):
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
15 |
|
16 |
# Generation configuration and safety settings
|
17 |
generation_config = {
|
18 |
+
"temperature": 0.9,
|
19 |
+
"top_p": 0.5,
|
20 |
+
"top_k": 5,
|
21 |
+
"max_output_tokens": 1000,
|
22 |
}
|
23 |
|
24 |
safety_settings = [
|
25 |
+
{
|
26 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
27 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
31 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
35 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
39 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
40 |
+
},
|
41 |
]
|
42 |
|
43 |
# Function to handle text summary requests
|
44 |
def text_summary(text, isNew=False):
|
45 |
+
global chat
|
46 |
+
|
47 |
+
if isNew or chat is None: # Start a new chat session
|
48 |
+
model = genai.GenerativeModel(
|
49 |
+
model_name="gemini-pro",
|
50 |
+
generation_config=generation_config,
|
51 |
+
safety_settings=safety_settings
|
52 |
+
)
|
53 |
+
chat = model.start_chat()
|
54 |
+
chat.send_message("""
|
55 |
+
Act as a financial advisor and generate financial summaries in a structured and tabular format. Follow these guidelines strictly:
|
56 |
+
|
57 |
+
- Start each section with a clear title in <strong> tags.
|
58 |
+
- For key metrics, use a table with two columns: one for the metric name and one for its value.
|
59 |
+
- Use bullet points only for listing risks and growth prospects.
|
60 |
+
- Ensure each section is clearly separated with line breaks.
|
61 |
+
- Do not use bold or italic formatting (, *), except for the specified HTML tags.
|
62 |
+
|
63 |
+
Example format:
|
64 |
+
|
65 |
+
<strong>Company Overview</strong><br/>
|
66 |
+
<p>Company Name: {Company Name}</p>
|
67 |
+
<p>Description: {Company Description}</p>
|
68 |
+
<br/><br/>
|
69 |
+
|
70 |
+
<strong>Stock Performance</strong><br/>
|
71 |
+
<p>Apple Inc. (AAPL) is a highly valued stock...</p>
|
72 |
+
<br/><br/>
|
73 |
+
|
74 |
+
<strong>Key Metrics</strong><br/>
|
75 |
+
<table>
|
76 |
+
<tr>
|
77 |
+
<th>Metric</th>
|
78 |
+
<th>Value</th>
|
79 |
+
</tr>
|
80 |
+
<tr>
|
81 |
+
<td>Market Capitalization</td>
|
82 |
+
<td>$2.7 trillion</td>
|
83 |
+
</tr>
|
84 |
+
<tr>
|
85 |
+
<td>Stock Price</td>
|
86 |
+
<td>$170 per share</td>
|
87 |
+
</tr>
|
88 |
+
<tr>
|
89 |
+
<td>EPS (TTM)</td>
|
90 |
+
<td>$6.15</td>
|
91 |
+
</tr>
|
92 |
+
<tr>
|
93 |
+
<td>P/E Ratio</td>
|
94 |
+
<td>24.34</td>
|
95 |
+
</tr>
|
96 |
+
</table>
|
97 |
+
<br/><br/>
|
98 |
+
|
99 |
+
<strong>Growth Prospects</strong><br/>
|
100 |
+
<ul>
|
101 |
+
<li>iPhone sales growth in emerging markets.</li>
|
102 |
+
<li>Expansion of services revenue.</li>
|
103 |
+
<li>Increased demand for wearable devices.</li>
|
104 |
+
<li>Development of AR/VR technologies.</li>
|
105 |
+
</ul>
|
106 |
+
<br/><br/>
|
107 |
+
|
108 |
+
<strong>Risks</strong><br/>
|
109 |
+
<ul>
|
110 |
+
<li>Competition from other technology companies.</li>
|
111 |
+
<li>Dependence on iPhone sales.</li>
|
112 |
+
<li>Economic downturns.</li>
|
113 |
+
<li>Supply chain disruptions and geopolitical risks.</li>
|
114 |
+
</ul>
|
115 |
+
<br/><br/>
|
116 |
+
|
117 |
+
<strong>Overall</strong><br/>
|
118 |
+
<p>Apple Inc. is a financially strong company with a history of innovation...</p>
|
119 |
+
<br/><br/>
|
120 |
+
""")
|
121 |
+
|
122 |
+
# Send message and return response
|
123 |
+
response = chat.send_message(text)
|
124 |
+
return response.text
|
125 |
|
126 |
# Streamlit UI
|
127 |
st.title("Financial Summary Chatbot")
|
|
|
132 |
|
133 |
# Button to submit the text
|
134 |
if st.button("Send"):
|
135 |
+
if chat_input.strip():
|
136 |
+
response = text_summary(chat_input)
|
137 |
+
st.write("### Response:")
|
138 |
+
st.markdown(response, unsafe_allow_html=True)
|
139 |
+
else:
|
140 |
+
st.warning("Please enter a message to send.")
|