eaglelandsonce commited on
Commit
e0c7cec
1 Parent(s): 8582c5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -2
app.py CHANGED
@@ -2,11 +2,58 @@ import os
2
  import time
3
  import uuid
4
  from typing import List, Tuple, Optional, Dict, Union
5
-
6
-
7
  import google.generativeai as genai
8
  import gradio as gr
9
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  print("google-generativeai:", genai.__version__)
12
 
@@ -165,6 +212,9 @@ upload_button_component = gr.UploadButton(
165
  label="Upload Images", file_count="multiple", file_types=["image"], scale=1
166
  )
167
  run_button_component = gr.Button(value="Run", variant="primary", scale=1)
 
 
 
168
  temperature_component = gr.Slider(
169
  minimum=0,
170
  maximum=1.0,
@@ -228,6 +278,7 @@ user_inputs = [
228
  chatbot_component
229
  ]
230
 
 
231
  bot_inputs = [
232
  google_key_component,
233
  upload_button_component,
@@ -244,6 +295,23 @@ with gr.Blocks() as demo:
244
  with gr.Tab("Company Analysis"):
245
  gr.HTML(TITLE1)
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
  with gr.Tab("Investment Strategy"):
249
  gr.HTML(TITLE2)
 
2
  import time
3
  import uuid
4
  from typing import List, Tuple, Optional, Dict, Union
 
 
5
  import google.generativeai as genai
6
  import gradio as gr
7
  from PIL import Image
8
+ from langchain.chat_models import ChatOpenAI
9
+ from langchain.prompts import ChatPromptTemplate
10
+ from langchain.chains import LLMChain, SequentialChain
11
+
12
+ # LangChain function for company analysis
13
+
14
+ def company_analysis(api_key: str, company_name: str) -> dict:
15
+
16
+ os.environ['OPENAI_API_KEY'] = api_key # Set the OpenAI API key as an environment variable
17
+ llm = ChatOpenAI()
18
+ '''
19
+ # Identify the email's language
20
+ template1 = "Return the language this email is written in:\n{email}.\nONLY return the language it was written in."
21
+ prompt1 = ChatPromptTemplate.from_template(template1)
22
+ chain_1 = LLMChain(llm=llm, prompt=prompt1, output_key="language")
23
+
24
+ # Translate the email to English
25
+ template2 = "Translate this email from {language} to English. Here is the email:\n" + email
26
+ prompt2 = ChatPromptTemplate.from_template(template2)
27
+ chain_2 = LLMChain(llm=llm, prompt=prompt2, output_key="translated_email")
28
+
29
+ # Provide a summary in English
30
+ template3 = "Create a short summary of this email:\n{translated_email}"
31
+ prompt3 = ChatPromptTemplate.from_template(template3)
32
+ chain_3 = LLMChain(llm=llm, prompt=prompt3, output_key="summary")
33
+
34
+ # Provide a reply in English
35
+ template4 = "Reply to the sender of the email giving a plausible reply based on the {summary} and a promise to address issues"
36
+ prompt4 = ChatPromptTemplate.from_template(template4)
37
+ chain_4 = LLMChain(llm=llm, prompt=prompt4, output_key="reply")
38
+
39
+ # Provide a translation back to the original language
40
+ template5 = "Translate the {reply} back to the original {language} of the email."
41
+ prompt5 = ChatPromptTemplate.from_template(template5)
42
+ chain_5 = LLMChain(llm=llm, prompt=prompt5, output_key="translated_reply")
43
+
44
+
45
+ seq_chain = SequentialChain(chains=[chain_1, chain_2, chain_3, chain_4, chain_5],
46
+ input_variables=['email'],
47
+ output_variables=['language', 'translated_email', 'summary', 'reply', 'translated_reply'],
48
+ verbose=True)
49
+ '''
50
+ return seq_chain(email)
51
+
52
+
53
+
54
+
55
+
56
+
57
 
58
  print("google-generativeai:", genai.__version__)
59
 
 
212
  label="Upload Images", file_count="multiple", file_types=["image"], scale=1
213
  )
214
  run_button_component = gr.Button(value="Run", variant="primary", scale=1)
215
+
216
+ run_button_analysis = gr.Button(value="Run", variant="primary", scale=1)
217
+
218
  temperature_component = gr.Slider(
219
  minimum=0,
220
  maximum=1.0,
 
278
  chatbot_component
279
  ]
280
 
281
+
282
  bot_inputs = [
283
  google_key_component,
284
  upload_button_component,
 
295
  with gr.Tab("Company Analysis"):
296
  gr.HTML(TITLE1)
297
 
298
+ run_button_analysis.click(
299
+ fn=company_analysis,
300
+ inputs=[
301
+ gr.inputs.Textbox(label="Enter your OpenAI API Key:", type="password"),
302
+ gr.inputs.Textbox(label="Enter the Company Name:")
303
+ ],
304
+ outputs=[
305
+ gr.outputs.Textbox(label="Language"),
306
+ gr.outputs.Textbox(label="Summary"),
307
+ gr.outputs.Textbox(label="Translated Email"),
308
+ gr.outputs.Textbox(label="Reply in English"),
309
+ gr.outputs.Textbox(label="Reply in Original Language")
310
+ ],
311
+ title="Chain Example: Language, Summary, Translate, Respond & Translate",
312
+ description="Translates an email to English, provides a summary, plausible reply and translates back to the sender"
313
+ )
314
+
315
 
316
  with gr.Tab("Investment Strategy"):
317
  gr.HTML(TITLE2)