Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from groq import Groq
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
client = Groq(
|
| 7 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def chat_with_groq(user_input, additional_context=None):
|
| 13 |
+
chat_completion = client.chat.completions.create(
|
| 14 |
+
messages=[
|
| 15 |
+
{
|
| 16 |
+
"role": "user",
|
| 17 |
+
"content": user_input,
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
model="llama-3.1-8b-instant",
|
| 21 |
+
)
|
| 22 |
+
return chat_completion.choices[0].message.content
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
demo = gr.ChatInterface(fn=chat_with_groq,
|
| 28 |
+
chatbot=gr.Chatbot(height=250),
|
| 29 |
+
textbox=gr.Textbox(placeholder="Ask me any question", scale=6),
|
| 30 |
+
title="Hey NOPE",
|
| 31 |
+
theme="Monochrome",
|
| 32 |
+
description="Welcome to the world of NOPE",
|
| 33 |
+
examples=["Need some content Idea", "Generate some Thumbnail Text"],
|
| 34 |
+
retry_btn=None,
|
| 35 |
+
undo_btn="Delete Previous",
|
| 36 |
+
clear_btn="Clear",)
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|