Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
-
import re
|
| 5 |
import requests
|
| 6 |
import gradio as gr
|
| 7 |
|
|
@@ -10,7 +9,14 @@ import gradio as gr
|
|
| 10 |
# ----------------------------------------------------------------------
|
| 11 |
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 12 |
GROQ_ENDPOINT = "https://api.groq.com/openai/v1/chat/completions"
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# ----------------------------------------------------------------------
|
| 16 |
# CSS (will be passed to demo.launch)
|
|
@@ -35,7 +41,7 @@ CSS = """
|
|
| 35 |
# ----------------------------------------------------------------------
|
| 36 |
# Helper to call Groq API
|
| 37 |
# ----------------------------------------------------------------------
|
| 38 |
-
def call_groq(messages):
|
| 39 |
"""
|
| 40 |
Sends a chat completion request to Groq and returns the assistant's reply.
|
| 41 |
"""
|
|
@@ -46,7 +52,7 @@ def call_groq(messages):
|
|
| 46 |
"Content-Type": "application/json"
|
| 47 |
}
|
| 48 |
payload = {
|
| 49 |
-
"model":
|
| 50 |
"messages": messages,
|
| 51 |
"temperature": 0.7
|
| 52 |
}
|
|
@@ -55,5 +61,5 @@ def call_groq(messages):
|
|
| 55 |
data = response.json()
|
| 56 |
# Extract the assistant's content
|
| 57 |
content = data["choices"][0]["message"]["content"]
|
| 58 |
-
#
|
| 59 |
if content.startswith("
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
import os
|
| 3 |
import json
|
|
|
|
| 4 |
import requests
|
| 5 |
import gradio as gr
|
| 6 |
|
|
|
|
| 9 |
# ----------------------------------------------------------------------
|
| 10 |
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
| 11 |
GROQ_ENDPOINT = "https://api.groq.com/openai/v1/chat/completions"
|
| 12 |
+
|
| 13 |
+
# Default model can be overridden by the user via the dropdown
|
| 14 |
+
DEFAULT_MODEL = os.environ.get("MODEL_NAME", "llama-3.1-8b-instant")
|
| 15 |
+
AVAILABLE_MODELS = [
|
| 16 |
+
"llama-3.3-70b-versatile",
|
| 17 |
+
"llama-3.1-8b-instant",
|
| 18 |
+
"qwen/qwen3-32b"
|
| 19 |
+
]
|
| 20 |
|
| 21 |
# ----------------------------------------------------------------------
|
| 22 |
# CSS (will be passed to demo.launch)
|
|
|
|
| 41 |
# ----------------------------------------------------------------------
|
| 42 |
# Helper to call Groq API
|
| 43 |
# ----------------------------------------------------------------------
|
| 44 |
+
def call_groq(messages, model):
|
| 45 |
"""
|
| 46 |
Sends a chat completion request to Groq and returns the assistant's reply.
|
| 47 |
"""
|
|
|
|
| 52 |
"Content-Type": "application/json"
|
| 53 |
}
|
| 54 |
payload = {
|
| 55 |
+
"model": model,
|
| 56 |
"messages": messages,
|
| 57 |
"temperature": 0.7
|
| 58 |
}
|
|
|
|
| 61 |
data = response.json()
|
| 62 |
# Extract the assistant's content
|
| 63 |
content = data["choices"][0]["message"]["content"]
|
| 64 |
+
# Remove surrounding markdown fences if present
|
| 65 |
if content.startswith("
|