|
""" |
|
app.py |
|
""" |
|
import os |
|
|
|
import gradio as gr |
|
from groq import Groq |
|
|
|
client = Groq(api_key=os.getenv('GROQ_API_KEY')) |
|
|
|
def autocomplete(text): |
|
if text != "": |
|
response = client.chat.completions.create( |
|
model='gemma-7b-it', |
|
messages=[ |
|
{ |
|
"role": "system", |
|
"content": "Du bist Jens, ein deutscher KI-Assistent und antwortest auf die Fragen der User möglichst kurz, knapp aber immer freundlich. Du antwortest dem User immer auf deutsch und in du-form an. Deine Antworten sollen immer umgangsprachlich sein." |
|
}, |
|
{ |
|
"role": "user", |
|
"content": text |
|
}], |
|
stream=True |
|
) |
|
|
|
partial_message = "" |
|
for chunk in response: |
|
if chunk.choices[0].delta.content is not None: |
|
partial_message = partial_message + chunk.choices[0].delta.content |
|
yield partial_message |
|
|
|
|
|
iface = gr.Interface( |
|
fn=autocomplete, |
|
inputs=gr.Textbox(lines=2, |
|
placeholder="Moin! 👋", |
|
label="Input Sentence"), |
|
outputs=gr.Markdown(), |
|
title="Turbo KI-Chat 🚀", |
|
description="Powered by Groq & Mistral", |
|
live=True, |
|
allow_flagging="never" |
|
) |
|
|
|
|
|
iface.launch(share=True) |