Gabriel C
Create app.py
a20cb09 verified
raw
history blame
1.27 kB
"""
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": "You are a polite and friendly assistant. If you receive NSFW inputs or requests, politely decline."}
{"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
# Create the Gradio interface with live updates
iface = gr.Interface(
fn=autocomplete,
inputs=gr.Textbox(lines=2,
placeholder="Hello πŸ‘‹",
label="Input Sentence"),
outputs="text",
title="Catch me if you can 🚝",
description="Type a sentence and see the autocomplete. The suggestion updates as you type!",
live=True, # Set live to True for real-time feedback
allow_flagging="never" # Disable flagging
)
# Launch the app
iface.launch()