cloud-sean commited on
Commit
13a2ed6
·
1 Parent(s): e8b8bf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -2,15 +2,18 @@ import os
2
  import openai
3
  from io import StringIO
4
  import sys
5
- import csv
6
  import gradio as gr
7
  from langchain.agents import create_csv_agent
8
  from langchain.chat_models import AzureChatOpenAI
9
-
10
 
11
  os.environ["OPENAI_API_TYPE"] = openai.api_type = "azure"
12
  os.environ["OPENAI_API_BASE"] = openai.api_base = "https://openai-endpoint.openai.azure.com/"
13
  os.environ["OPENAI_API_KEY"] = openai.api_key = os.environ["OPENAI_API_KEY"]
 
 
 
14
 
15
  class Capturing(list):
16
  def __enter__(self):
@@ -24,8 +27,10 @@ class Capturing(list):
24
 
25
  def answer_question(input_file, question):
26
  agent = create_csv_agent(llm, input_file.name, verbose=True)
 
27
  with Capturing() as printed_text:
28
  answer = agent.run(question)
 
29
  import re
30
  text = '\n'.join(printed_text) + '\n' + str(answer)
31
  # Remove all escape characters
@@ -38,9 +43,6 @@ def answer_question(input_file, question):
38
  text = text.strip()
39
  return text
40
 
41
-
42
- llm = AzureChatOpenAI(openai_api_base="https://openai-endpoint.openai.azure.com/", openai_api_key=openai.api_key, deployment_name="gpt4", model_name="gpt-4", openai_api_version="2023-03-15-preview")
43
-
44
  with gr.Blocks(css="footer {visibility: hidden}", title="CSV Copilot") as demo:
45
  csv_file = gr.State([])
46
  csv_file = gr.File(label="CSV File", accept=".csv")
 
2
  import openai
3
  from io import StringIO
4
  import sys
5
+
6
  import gradio as gr
7
  from langchain.agents import create_csv_agent
8
  from langchain.chat_models import AzureChatOpenAI
9
+ from langchain.llms import AzureOpenAI
10
 
11
  os.environ["OPENAI_API_TYPE"] = openai.api_type = "azure"
12
  os.environ["OPENAI_API_BASE"] = openai.api_base = "https://openai-endpoint.openai.azure.com/"
13
  os.environ["OPENAI_API_KEY"] = openai.api_key = os.environ["OPENAI_API_KEY"]
14
+ openai.api_version = "2023-03-15-preview"
15
+
16
+ llm = AzureOpenAI(deployment_name="davinci003", model_name="text-davinci-003")
17
 
18
  class Capturing(list):
19
  def __enter__(self):
 
27
 
28
  def answer_question(input_file, question):
29
  agent = create_csv_agent(llm, input_file.name, verbose=True)
30
+ question = question
31
  with Capturing() as printed_text:
32
  answer = agent.run(question)
33
+
34
  import re
35
  text = '\n'.join(printed_text) + '\n' + str(answer)
36
  # Remove all escape characters
 
43
  text = text.strip()
44
  return text
45
 
 
 
 
46
  with gr.Blocks(css="footer {visibility: hidden}", title="CSV Copilot") as demo:
47
  csv_file = gr.State([])
48
  csv_file = gr.File(label="CSV File", accept=".csv")