peterpull commited on
Commit
b2a43df
·
1 Parent(s): ca3537b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -39
app.py CHANGED
@@ -1,45 +1,10 @@
1
- from gpt_index import GPTSimpleVectorIndex
2
- from langchain import OpenAI
3
  import gradio as gr
4
- import sys
5
- import os
6
- import datetime
7
 
8
- os.environ["OPENAI_API_KEY"] = os.environ['SECRET_CODE']
9
 
 
 
10
 
11
- def get_index(index_file_path):
12
- if os.path.exists(index_file_path):
13
- return GPTSimpleVectorIndex.load_from_disk(index_file_path)
14
- else:
15
- print(f"Error: '{index_file_path}' does not exist.")
16
- sys.exit()
17
 
 
18
 
19
- def chatbot(input_text, mentioned_person='Mediator John Haynes'):
20
- index = get_index('index.json')
21
- prompt = f"You are {mentioned_person}: {input_text}\n\n At the end of your answer ask a provocative question."
22
- response = index.query(prompt, response_mode="compact")
23
-
24
- # Save chat log
25
- current_time = datetime.datetime.now()
26
- current_time_str = current_time.strftime("%Y-%m-%d_%H-%M-%S")
27
- chat_log_filename = "chathistory.txt"
28
- chat_log_filepath = os.path.join('chathistory', chat_log_filename)
29
- with open(chat_log_filepath, "a") as f:
30
- f.write(f"Chat at {current_time_str}\n")
31
- f.write(f"User: {input_text}\n")
32
- f.write(f"Chatbot: {response.response}\n\n")
33
-
34
- return response.response
35
-
36
- print('hello there!!!')
37
-
38
- iface = gr.Interface(fn=chatbot,
39
- inputs=gr.inputs.Textbox("Enter your question"),
40
- outputs="text",
41
- title="AI Chatbot trained on J. Haynes mediation material, v0.1",
42
- description="test")
43
- iface.launch()
44
-
45
- print('hello there222!!!')
 
 
 
1
  import gradio as gr
 
 
 
2
 
 
3
 
4
+ def greet(name):
5
+ return "Hello " + name
6
 
 
 
 
 
 
 
7
 
8
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
9
 
10
+ demo.launch()