Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Liste der verfügbaren Modelle
|
6 |
+
MODELS = [
|
7 |
+
"llama3-70b-8192",
|
8 |
+
"llama3-8b-8192",
|
9 |
+
"qwen-qwq-32b",
|
10 |
+
"mistral-saba-24b",
|
11 |
+
"qwen-2.5-coder-32b",
|
12 |
+
"qwen-2.5-32b",
|
13 |
+
"deepseek-r1-distill-qwen-32b",
|
14 |
+
"deepseek-r1-distill-llama-70b-specdec",
|
15 |
+
"deepseek-r1-distill-llama-70b",
|
16 |
+
"llama-3.2-3b-preview",
|
17 |
+
"llama-3.2-11b-vision-preview"
|
18 |
+
]
|
19 |
+
|
20 |
+
def predict(model, input_text):
|
21 |
+
# Initialisiere den Groq Client
|
22 |
+
client = OpenAI(
|
23 |
+
base_url="https://api.groq.com/openai/v1",
|
24 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
25 |
+
)
|
26 |
+
|
27 |
+
# Sende Anfrage an die Groq API
|
28 |
+
completion = client.chat.completions.create(
|
29 |
+
model=model,
|
30 |
+
messages=[
|
31 |
+
{
|
32 |
+
"role": "user",
|
33 |
+
"content": input_text
|
34 |
+
}
|
35 |
+
],
|
36 |
+
temperature=0.5,
|
37 |
+
max_tokens=1024,
|
38 |
+
top_p=1,
|
39 |
+
stream=False,
|
40 |
+
stop=None,
|
41 |
+
)
|
42 |
+
|
43 |
+
return completion.choices[0].message.content
|
44 |
+
|
45 |
+
# Erstelle die Gradio Oberfläche
|
46 |
+
with gr.Blocks() as demo:
|
47 |
+
gr.Markdown("# Groq API Chat Interface")
|
48 |
+
|
49 |
+
with gr.Row():
|
50 |
+
model_dropdown = gr.Dropdown(
|
51 |
+
choices=MODELS,
|
52 |
+
value=MODELS[0],
|
53 |
+
label="Wähle ein Modell"
|
54 |
+
)
|
55 |
+
|
56 |
+
with gr.Row():
|
57 |
+
input_text = gr.Textbox(
|
58 |
+
label="Eingabe",
|
59 |
+
placeholder="Gib deine Nachricht hier ein..."
|
60 |
+
)
|
61 |
+
|
62 |
+
output_text = gr.Textbox(label="Antwort", interactive=False)
|
63 |
+
|
64 |
+
submit_btn = gr.Button("Absenden")
|
65 |
+
submit_btn.click(
|
66 |
+
fn=predict,
|
67 |
+
inputs=[model_dropdown, input_text],
|
68 |
+
outputs=output_text
|
69 |
+
)
|
70 |
+
|
71 |
+
if __name__ == "__main__":
|
72 |
+
demo.launch()
|