Spaces:
Build error
Build error
Commit
•
98df760
0
Parent(s):
Duplicate from ysharma/ChatinterfaceTests
Browse filesCo-authored-by: yuvraj sharma <ysharma@users.noreply.huggingface.co>
- .gitattributes +35 -0
- README.md +14 -0
- app.py +76 -0
- requirements.txt +4 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: ChatinterfaceTests
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.36.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: ysharma/ChatinterfaceTests
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import openai
|
4 |
+
import gradio as gr
|
5 |
+
from gradio import ChatInterface
|
6 |
+
import time
|
7 |
+
|
8 |
+
# Get the value of the openai_api_key from environment variable
|
9 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
+
|
11 |
+
# Import things that are needed generically from langchain
|
12 |
+
from langchain import LLMMathChain, SerpAPIWrapper
|
13 |
+
from langchain.agents import AgentType, initialize_agent, load_tools
|
14 |
+
from langchain.chat_models import ChatOpenAI
|
15 |
+
from langchain.tools import BaseTool, StructuredTool, Tool, tool
|
16 |
+
from langchain.tools import MoveFileTool, format_tool_to_openai_function
|
17 |
+
from langchain.schema import (
|
18 |
+
AIMessage,
|
19 |
+
HumanMessage,
|
20 |
+
SystemMessage
|
21 |
+
)
|
22 |
+
from langchain.utilities import WikipediaAPIWrapper
|
23 |
+
from langchain.tools import AIPluginTool
|
24 |
+
|
25 |
+
# Question- how can one set up a system message for their Chatbot while using ChatInterface
|
26 |
+
# Example system message : system = SystemMessage(content = "You are a helpful AI assistant")
|
27 |
+
|
28 |
+
# driver
|
29 |
+
def predict_langchain(user_input, chatbot):
|
30 |
+
|
31 |
+
print(f"Chatbot : {chatbot}")
|
32 |
+
chat = ChatOpenAI(temperature=1.0, streaming=True, model='gpt-3.5-turbo-0613')
|
33 |
+
messages=[]
|
34 |
+
|
35 |
+
for conv in chatbot:
|
36 |
+
human = HumanMessage(content=conv[0])
|
37 |
+
ai = AIMessage(content=conv[1])
|
38 |
+
messages.append(human)
|
39 |
+
messages.append(ai)
|
40 |
+
|
41 |
+
messages.append(HumanMessage(content=user_input))
|
42 |
+
|
43 |
+
# getting gpt3.5's response
|
44 |
+
gpt_response = chat(messages)
|
45 |
+
return gpt_response.content
|
46 |
+
|
47 |
+
def predict(inputs, chatbot):
|
48 |
+
|
49 |
+
print(f"Chatbot : {chatbot}")
|
50 |
+
messages = []
|
51 |
+
for conv in chatbot:
|
52 |
+
user = conv[0]
|
53 |
+
messages.append({"role": "user", "content":user })
|
54 |
+
if conv[1] is None:
|
55 |
+
break
|
56 |
+
assistant = conv[1]
|
57 |
+
messages.append({"role": "assistant", "content":assistant})
|
58 |
+
|
59 |
+
# a ChatCompletion request
|
60 |
+
response = openai.ChatCompletion.create(
|
61 |
+
model='gpt-3.5-turbo',
|
62 |
+
messages= messages, # example : [{'role': 'user', 'content': "What is life? Answer in three words."}],
|
63 |
+
temperature=1.0,
|
64 |
+
stream=True # for streaming the output to chatbot
|
65 |
+
)
|
66 |
+
|
67 |
+
partial_message = ""
|
68 |
+
for chunk in response:
|
69 |
+
if len(chunk['choices'][0]['delta']) != 0:
|
70 |
+
print(chunk['choices'][0]['delta']['content'])
|
71 |
+
partial_message = partial_message + chunk['choices'][0]['delta']['content']
|
72 |
+
yield partial_message
|
73 |
+
|
74 |
+
#ChatInterface(predict, delete_last_btn="❌Delete").queue().launch(debug=True)
|
75 |
+
|
76 |
+
gr.ChatInterface(predict, delete_last_btn="del").queue().launch(share=False, debug=True) #examples=["How are you?", "What's up?"],
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#pydatntic==1.*
|
2 |
+
https://gradio-builds.s3.amazonaws.com/6257d616c40af7653f743cf9ef4f7b0a9cdabef2/gradio-3.36.1-py3-none-any.whl
|
3 |
+
openai
|
4 |
+
langchain
|