File size: 1,314 Bytes
a20cb09
 
 
 
 
 
 
 
 
 
 
 
 
 
adcde1c
 
 
 
 
a20cb09
 
 
 
 
 
 
 
 
2a0bd98
 
 
 
 
178ec6e
a20cb09
 
 
 
 
 
8bd5c9a
178ec6e
d120fa4
a20cb09
2a0bd98
 
a20cb09
2a0bd98
 
a20cb09
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
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": "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
              
css = """
.generating {
    display: none
}
"""

# Create the Gradio interface with live updates
iface = gr.Interface(
    fn=autocomplete,
    inputs=gr.Textbox(lines=2,
                      placeholder="Hello 👋",
                      label="Input Sentence"),
    outputs=gr.Markdown(),
    title="Catch Me If You Can 🐰",
    description="Powered by Groq & Gemma",
    live=True,  # Set live to True for real-time feedback
    allow_flagging="never",  # Disable flagging
    css=css
)
iface.dependencies[0]['show_progress'] = "hidden"
iface.dependencies[2]['show_progress'] = "hidden"

# Launch the app
iface.launch()