ShermanAI commited on
Commit
7534eaf
·
1 Parent(s): 23345a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -33
app.py CHANGED
@@ -1,4 +1,3 @@
1
- '''
2
  import subprocess
3
  subprocess.check_call(["pip", "install", "-q", "openai"])
4
  subprocess.check_call(["pip", "install", "-q", "gradio", "transformers", "python-dotenv"])
@@ -35,35 +34,4 @@ examples = [
35
  inputs = [gr.inputs.Textbox(label="Talk to ChatSherman: "), "state"]
36
  outputs = ["chatbot", "state"]
37
  interface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
38
- interface.launch(debug=True)
39
- '''
40
- python -m pip install --upgrade pip
41
- import subprocess
42
- subprocess.check_call(["pip", "install", "-q", "openai"])
43
- subprocess.check_call(["pip", "install", "-q", "gradio", "transformers", "python-dotenv"])
44
- import openai
45
- import gradio as gr
46
-
47
- openai.api_key = "OPENAI_API_KEY"
48
-
49
- def predict(message, history):
50
- history_openai_format = []
51
- for human, assistant in history:
52
- history_openai_format.append({"role": "user", "content": human })
53
- history_openai_format.append({"role": "assistant", "content":assistant})
54
- history_openai_format.append({"role": "user", "content": message})
55
-
56
- response = openai.ChatCompletion.create(
57
- model='gpt-3.5-turbo',
58
- messages= history_openai_format,
59
- temperature=1.0,
60
- stream=True
61
- )
62
-
63
- partial_message = ""
64
- for chunk in response:
65
- if len(chunk['choices'][0]['delta']) != 0:
66
- partial_message = partial_message + chunk['choices'][0]['delta']['content']
67
- yield partial_message
68
-
69
- gr.ChatInterface(predict).queue().launch()
 
 
1
  import subprocess
2
  subprocess.check_call(["pip", "install", "-q", "openai"])
3
  subprocess.check_call(["pip", "install", "-q", "gradio", "transformers", "python-dotenv"])
 
34
  inputs = [gr.inputs.Textbox(label="Talk to ChatSherman: "), "state"]
35
  outputs = ["chatbot", "state"]
36
  interface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
37
+ interface.launch(debug=True)