Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from groq import Groq
|
| 4 |
+
|
| 5 |
+
def random_response(message, history):
|
| 6 |
+
client = Groq(
|
| 7 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
chat_completion = client.chat.completions.create(
|
| 11 |
+
messages=[
|
| 12 |
+
{
|
| 13 |
+
"role": "user",
|
| 14 |
+
"content": message,
|
| 15 |
+
}
|
| 16 |
+
],
|
| 17 |
+
model="meta-llama/llama-4-scout-17b-16e-instruct",
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
return chat_completion.choices[0].message.content
|
| 21 |
+
|
| 22 |
+
demo = gr.ChatInterface(random_response, type="messages", autofocus=False)
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
demo.launch()
|