Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
OPENAI_API_KEY = 'sk-OikOSREhj5W13P_sJlh85ZAKXla3l3lVLaQ4JtTXR2T3BlbkFJMLCnZHaaR9GJRJWsbMX_eo6c79ZRWJ3-S2hQ89znQA' #Replace your openai api key
|
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.42.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: chatbot
|
3 |
+
app_file: main.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 4.42.0
|
|
|
|
|
6 |
---
|
|
|
|
main.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openai import OpenAI
|
2 |
+
import gradio as gr
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
+
|
7 |
+
client = OpenAI()
|
8 |
+
|
9 |
+
|
10 |
+
def generate_response(message, history):
|
11 |
+
formatted_history = []
|
12 |
+
for user, assistant in history:
|
13 |
+
formatted_history.append({"role": "user", "content": user})
|
14 |
+
formatted_history.append({"role": "assistant", "content": assistant})
|
15 |
+
|
16 |
+
formatted_history.append({"role": "user", "content": message})
|
17 |
+
|
18 |
+
response = client.chat.completions.create(model='gpt-3.5-turbo',
|
19 |
+
messages=formatted_history,
|
20 |
+
temperature=1.0)
|
21 |
+
|
22 |
+
return response.choices[0].message.content
|
23 |
+
|
24 |
+
|
25 |
+
gr.ChatInterface(generate_response,
|
26 |
+
chatbot=gr.Chatbot(height=300),
|
27 |
+
textbox=gr.Textbox(placeholder="You can ask me anything", container=False, scale=7),
|
28 |
+
title="OpenAI Chat Bot",
|
29 |
+
retry_btn=None,
|
30 |
+
undo_btn="Delete Previous",
|
31 |
+
clear_btn="Clear").launch(share=True)
|
32 |
+
gr.ChatInterface(generate_response).launch()
|