productizationlabs
commited on
Commit
·
7ab0b3d
1
Parent(s):
c9b77d2
Upload app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,33 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
_A='content'
|
6 |
-
import os,gradio as gr,json,requests,openai
|
7 |
-
try:openai.api_key=os.environ['OPENAI_API_KEY']
|
8 |
-
except KeyError:
|
9 |
-
error_message='System is at capacity right now.Please try again later';print(error_message)
|
10 |
-
def chatbot(input):return error_message
|
11 |
-
else:messages=[{_B:_D,_A:_E}]
|
12 |
-
messages=[{_B:_D,_A:_E}]
|
13 |
API_URL='https://api.openai.com/v1/chat/completions'
|
|
|
14 |
top_p_chatgpt=1.0
|
15 |
temperature_chatgpt=1.0
|
16 |
-
def
|
17 |
-
|
18 |
-
if
|
19 |
-
|
20 |
-
for
|
21 |
-
|
22 |
-
|
23 |
-
for
|
24 |
-
|
25 |
-
if
|
26 |
-
|
27 |
-
|
28 |
-
D=D+json.loads(B[6:])[W][0][X][_A]
|
29 |
-
if M==0:A.append(' '+D)
|
30 |
-
else:A[-1]=D
|
31 |
-
a=[(A[B],A[B+1])for B in range(0,len(A)-1,2)];M+=1;yield(a,A,F)
|
32 |
def reset_textbox():return gr.update(value='')
|
33 |
def reset_chat(chatbot,state):return None,[]
|
34 |
-
with gr.Blocks(css='#col_container {width: 1000px; margin-left: auto; margin-right: auto;}\n #chatgpt {height: 400px; overflow: auto;}} ',theme=gr.themes.Default(primary_hue='slate'))as
|
35 |
with gr.Row():
|
36 |
with gr.Column(scale=14):
|
37 |
with gr.Box():
|
38 |
with gr.Row():
|
39 |
-
with gr.Column(scale=13):inputs=gr.Textbox(label='Ask
|
40 |
-
with gr.Column(scale=1):b1=gr.Button('Submit',elem_id='submit').style(full_width=
|
41 |
state_chatgpt=gr.State([])
|
42 |
with gr.Box():
|
43 |
-
with gr.Row():chatbot_chatgpt=gr.Chatbot(elem_id='chatgpt',label='Conversational AI
|
44 |
-
chat_counter_chatgpt=gr.Number(value=0,visible=False,precision=0);inputs.submit(reset_textbox,[],[inputs]);b1.click(
|
|
|
1 |
+
import os
|
2 |
+
from gpt_index import SimpleDirectoryReader,GPTSimpleVectorIndex,LLMPredictor,PromptHelper
|
3 |
+
from langchain import OpenAI
|
4 |
+
import gradio as gr,openai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
API_URL='https://api.openai.com/v1/chat/completions'
|
6 |
+
openai.api_key=os.environ['OPENAI_API_KEY']
|
7 |
top_p_chatgpt=1.0
|
8 |
temperature_chatgpt=1.0
|
9 |
+
def predict_chatgpt(inputs,chat_counter_chatgpt,chatbot_chatgpt=[],history=[]):
|
10 |
+
M='user';J='content';I='role';D=chat_counter_chatgpt;C=inputs;A=history
|
11 |
+
if D!=0:
|
12 |
+
E=[]
|
13 |
+
for K in chatbot_chatgpt:F={};F[I]=M;F[J]=K[0];G={};G[I]='assistant';G[J]=K[1];E.append(F);E.append(G)
|
14 |
+
H={};H[I]=M;H[J]=C;E.append(H)
|
15 |
+
D+=1;A.append('You asked: '+C);N=GPTSimpleVectorIndex.load_from_disk('PLIndex.json');O=N.query(C);P=O.response.split();L=0;B='';S=0
|
16 |
+
for Q in P:
|
17 |
+
B=B+' '+Q
|
18 |
+
if L==0:A.append(' '+B)
|
19 |
+
else:A[-1]=B
|
20 |
+
R=[(A[B],A[B+1])for B in range(0,len(A)-1,2)];L+=1;yield(R,A,D)
|
|
|
|
|
|
|
|
|
21 |
def reset_textbox():return gr.update(value='')
|
22 |
def reset_chat(chatbot,state):return None,[]
|
23 |
+
with gr.Blocks(css='#col_container {width: 1000px; margin-left: auto; margin-right: auto;}\n #chatgpt {height: 400px; overflow: auto;}} ',theme=gr.themes.Default(primary_hue='slate'))as PLCoversationalAI:
|
24 |
with gr.Row():
|
25 |
with gr.Column(scale=14):
|
26 |
with gr.Box():
|
27 |
with gr.Row():
|
28 |
+
with gr.Column(scale=13):inputs=gr.Textbox(label='Ask anything about Productization Labs ⤵️ Try : Who is Gopala')
|
29 |
+
with gr.Column(scale=1):b1=gr.Button('Submit',elem_id='submit').style(full_width=True);b2=gr.Button('Clear',elem_id='clear').style(full_width=True)
|
30 |
state_chatgpt=gr.State([])
|
31 |
with gr.Box():
|
32 |
+
with gr.Row():chatbot_chatgpt=gr.Chatbot(elem_id='chatgpt',label='Productization Labs Conversational AI')
|
33 |
+
chat_counter_chatgpt=gr.Number(value=0,visible=False,precision=0);inputs.submit(reset_textbox,[],[inputs]);b1.click(predict_chatgpt,[inputs,chat_counter_chatgpt,chatbot_chatgpt,state_chatgpt],[chatbot_chatgpt,state_chatgpt]);b2.click(reset_chat,[chatbot_chatgpt,state_chatgpt],[chatbot_chatgpt,state_chatgpt]);PLCoversationalAI.queue(concurrency_count=16).launch(height=2500,debug=True)
|