Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,38 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from groq import Groq
|
4 |
-
|
5 |
|
6 |
groq_client = Groq(
|
7 |
api_key=os.environ.get("GROQ_API_KEY"),
|
8 |
)
|
9 |
|
10 |
-
|
11 |
-
|
12 |
|
13 |
def store_conversation(user_input, bot_response):
|
14 |
# Truncate bot_response if it exceeds 2000 characters
|
15 |
truncated_response = bot_response[:1997] + "..." if len(bot_response) > 2000 else bot_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
try:
|
17 |
-
|
18 |
-
|
19 |
-
properties={
|
20 |
-
"User Input": {"title": [{"text": {"content": user_input}}]},
|
21 |
-
"Bot Response": {"rich_text": [{"text": {"content": truncated_response}}]}
|
22 |
-
}
|
23 |
-
)
|
24 |
print("Conversation stored successfully")
|
25 |
-
except
|
26 |
print(f"Error storing conversation: {str(e)}")
|
27 |
print("Make sure the Notion database is shared with your integration and the database ID is correct.")
|
28 |
|
@@ -50,6 +60,6 @@ demo = gr.ChatInterface(fn=chat_with_groq,
|
|
50 |
clear_btn="Clear",)
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
-
print(f"Using Notion database ID: {
|
54 |
print("Make sure the Notion database is shared with your integration.")
|
55 |
demo.launch()
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from groq import Groq
|
4 |
+
import requests
|
5 |
|
6 |
groq_client = Groq(
|
7 |
api_key=os.environ.get("GROQ_API_KEY"),
|
8 |
)
|
9 |
|
10 |
+
NOTION_TOKEN = os.environ.get("NOTION_TOKEN")
|
11 |
+
NOTION_DATABASE_ID = "4fc0a081f0a84257879d6f7638e368b9"
|
12 |
|
13 |
def store_conversation(user_input, bot_response):
|
14 |
# Truncate bot_response if it exceeds 2000 characters
|
15 |
truncated_response = bot_response[:1997] + "..." if len(bot_response) > 2000 else bot_response
|
16 |
+
|
17 |
+
url = f"https://api.notion.com/v1/pages"
|
18 |
+
headers = {
|
19 |
+
"Authorization": f"Bearer {NOTION_TOKEN}",
|
20 |
+
"Content-Type": "application/json",
|
21 |
+
"Notion-Version": "2022-06-28"
|
22 |
+
}
|
23 |
+
data = {
|
24 |
+
"parent": {"database_id": NOTION_DATABASE_ID},
|
25 |
+
"properties": {
|
26 |
+
"User Input": {"title": [{"text": {"content": user_input}}]},
|
27 |
+
"Bot Response": {"rich_text": [{"text": {"content": truncated_response}}]}
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
try:
|
32 |
+
response = requests.post(url, headers=headers, json=data)
|
33 |
+
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
34 |
print("Conversation stored successfully")
|
35 |
+
except requests.exceptions.RequestException as e:
|
36 |
print(f"Error storing conversation: {str(e)}")
|
37 |
print("Make sure the Notion database is shared with your integration and the database ID is correct.")
|
38 |
|
|
|
60 |
clear_btn="Clear",)
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
+
print(f"Using Notion database ID: {NOTION_DATABASE_ID}")
|
64 |
print("Make sure the Notion database is shared with your integration.")
|
65 |
demo.launch()
|