Gabriel C commited on
Commit
a20cb09
1 Parent(s): d3f4ffa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ app.py
3
+ """
4
+ import os
5
+
6
+ import gradio as gr
7
+ from groq import Groq
8
+
9
+ client = Groq(api_key=os.getenv('GROQ_API_KEY'))
10
+
11
+ def autocomplete(text):
12
+ if text != "":
13
+ response = client.chat.completions.create(
14
+ model='gemma-7b-it',
15
+ messages=[{"role": "system", "content": "You are a polite and friendly assistant. If you receive NSFW inputs or requests, politely decline."}
16
+ {"role": "user", "content": text}],
17
+ stream=True
18
+ )
19
+
20
+ partial_message = ""
21
+ for chunk in response:
22
+ if chunk.choices[0].delta.content is not None:
23
+ partial_message = partial_message + chunk.choices[0].delta.content
24
+ yield partial_message
25
+
26
+ # Create the Gradio interface with live updates
27
+ iface = gr.Interface(
28
+ fn=autocomplete,
29
+ inputs=gr.Textbox(lines=2,
30
+ placeholder="Hello 👋",
31
+ label="Input Sentence"),
32
+ outputs="text",
33
+ title="Catch me if you can 🚝",
34
+ description="Type a sentence and see the autocomplete. The suggestion updates as you type!",
35
+ live=True, # Set live to True for real-time feedback
36
+ allow_flagging="never" # Disable flagging
37
+ )
38
+
39
+ # Launch the app
40
+ iface.launch()