Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,13 @@ import os
|
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
from google.colab import userdata # Secure storage for API keys in Colab
|
| 6 |
-
|
| 7 |
groq_api_key = userdata.get("GROQ_API_KEY")
|
| 8 |
-
|
| 9 |
-
# Define the URL for the Groq API endpoint
|
| 10 |
url = "https://api.groq.com/openai/v1/chat/completions"
|
| 11 |
|
| 12 |
-
# Set the headers for the API request
|
| 13 |
headers = {
|
| 14 |
"Authorization": f"Bearer {groq_api_key}"
|
| 15 |
}
|
| 16 |
|
| 17 |
-
# Function to interact with Groq API
|
| 18 |
def chat_with_groq(user_input):
|
| 19 |
body = {
|
| 20 |
"model": "llama-3.1-8b-instant",
|
|
@@ -30,7 +24,6 @@ def chat_with_groq(user_input):
|
|
| 30 |
else:
|
| 31 |
return f"Error: {response.json()}"
|
| 32 |
|
| 33 |
-
# Create Gradio interface
|
| 34 |
interface = gr.Interface(
|
| 35 |
fn=chat_with_groq,
|
| 36 |
inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
|
|
@@ -39,5 +32,4 @@ interface = gr.Interface(
|
|
| 39 |
description="Type your question below and get a response powered by Groq's Llama 3.1-8B model."
|
| 40 |
)
|
| 41 |
|
| 42 |
-
# Launch Gradio app
|
| 43 |
interface.launch()
|
|
|
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
|
|
|
| 5 |
groq_api_key = userdata.get("GROQ_API_KEY")
|
|
|
|
|
|
|
| 6 |
url = "https://api.groq.com/openai/v1/chat/completions"
|
| 7 |
|
|
|
|
| 8 |
headers = {
|
| 9 |
"Authorization": f"Bearer {groq_api_key}"
|
| 10 |
}
|
| 11 |
|
|
|
|
| 12 |
def chat_with_groq(user_input):
|
| 13 |
body = {
|
| 14 |
"model": "llama-3.1-8b-instant",
|
|
|
|
| 24 |
else:
|
| 25 |
return f"Error: {response.json()}"
|
| 26 |
|
|
|
|
| 27 |
interface = gr.Interface(
|
| 28 |
fn=chat_with_groq,
|
| 29 |
inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
|
|
|
|
| 32 |
description="Type your question below and get a response powered by Groq's Llama 3.1-8B model."
|
| 33 |
)
|
| 34 |
|
|
|
|
| 35 |
interface.launch()
|