Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from groq import Groq
|
4 |
+
from notion_client import Client
|
5 |
+
|
6 |
+
groq_client = Groq(
|
7 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
8 |
+
)
|
9 |
+
|
10 |
+
notion_client = Client(auth=os.environ.get("NOTION_API_KEY"))
|
11 |
+
notion_database_id = "4fc0a081f0a84257879d6f7638e368b9"
|
12 |
+
|
13 |
+
def store_conversation(user_input, bot_response):
|
14 |
+
notion_client.pages.create(
|
15 |
+
parent={"database_id": notion_database_id},
|
16 |
+
properties={
|
17 |
+
"User Input": {"title": [{"text": {"content": user_input}}]},
|
18 |
+
"Bot Response": {"rich_text": [{"text": {"content": bot_response}}]}
|
19 |
+
}
|
20 |
+
)
|
21 |
+
|
22 |
+
def chat_with_groq(user_input, additional_context=None):
|
23 |
+
chat_completion = groq_client.chat.completions.create(
|
24 |
+
messages=[
|
25 |
+
{
|
26 |
+
"role": "user",
|
27 |
+
"content": user_input,
|
28 |
+
}
|
29 |
+
],
|
30 |
+
model="llama-3.1-8b-instant",
|
31 |
+
)
|
32 |
+
bot_response = chat_completion.choices[0].message.content
|
33 |
+
store_conversation(user_input, bot_response)
|
34 |
+
return bot_response
|
35 |
+
|
36 |
+
demo = gr.ChatInterface(fn=chat_with_groq,
|
37 |
+
textbox=gr.Textbox(placeholder="Ask me any question"),
|
38 |
+
title="Hey NOPE", theme="Monochrome",
|
39 |
+
description="Welcome to the world of NOPE",
|
40 |
+
examples=["Need some content Idea", "Generate some Thumbnail Text"],
|
41 |
+
retry_btn=None,
|
42 |
+
undo_btn="Delete Previous",
|
43 |
+
clear_btn="Clear",)
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
demo.launch()
|