|
import gradio as gr |
|
from openai import OpenAI |
|
import os |
|
from IPython.display import display, Markdown |
|
|
|
|
|
MODELS = [ |
|
"llama3-70b-8192", |
|
"llama3-8b-8192", |
|
"qwen-qwq-32b", |
|
"mistral-saba-24b", |
|
"qwen-2.5-coder-32b", |
|
"qwen-2.5-32b", |
|
"deepseek-r1-distill-qwen-32b", |
|
"deepseek-r1-distill-llama-70b-specdec", |
|
"deepseek-r1-distill-llama-70b", |
|
"llama-3.2-3b-preview", |
|
"llama-3.2-11b-vision-preview" |
|
] |
|
|
|
def predict(model, input_text): |
|
|
|
client = OpenAI( |
|
base_url="https://api.groq.com/openai/v1", |
|
api_key=os.environ.get("GROQ_API_KEY"), |
|
) |
|
|
|
|
|
completion = client.chat.completions.create( |
|
model=model, |
|
messages=[ |
|
{ |
|
"role": "user", |
|
"content": input_text |
|
} |
|
], |
|
temperature=0.1, |
|
max_tokens=4096, |
|
top_p=1, |
|
stream=False, |
|
stop=None, |
|
) |
|
|
|
|
|
response = completion.choices[0].message.content |
|
|
|
|
|
display(Markdown(f"**Antwort des Modells ({model}):**\n\n{response}")) |
|
|
|
return response |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Groq API Chat Interface") |
|
|
|
with gr.Row(): |
|
model_dropdown = gr.Dropdown( |
|
choices=MODELS, |
|
value=MODELS[0], |
|
label="Wähle ein Modell" |
|
) |
|
|
|
output_text = gr.Markdown() |
|
|
|
with gr.Row(): |
|
input_text = gr.Textbox() |
|
|
|
input_text.submit( |
|
fn=predict, |
|
inputs=[model_dropdown, input_text], |
|
outputs=output_text |
|
) |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |