App.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=[
|
| 16 |
+
{
|
| 17 |
+
"role": "user",
|
| 18 |
+
"content": text
|
| 19 |
+
}],
|
| 20 |
+
stream=True
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
partial_message = ""
|
| 24 |
+
for chunk in response:
|
| 25 |
+
if chunk.choices[0].delta.content is not None:
|
| 26 |
+
partial_message = partial_message + chunk.choices[0].delta.content
|
| 27 |
+
yield partial_message
|
| 28 |
+
|
| 29 |
+
css = """
|
| 30 |
+
.generating {
|
| 31 |
+
display: none
|
| 32 |
+
}
|
| 33 |
+
"""
|
| 34 |
+
# Create the Gradio interface with live updates
|
| 35 |
+
iface = gr.Interface(
|
| 36 |
+
fn=autocomplete,
|
| 37 |
+
inputs=gr.Textbox(lines=2,
|
| 38 |
+
placeholder="Hello 👋",
|
| 39 |
+
label="Input Sentence"),
|
| 40 |
+
outputs=gr.Markdown(),
|
| 41 |
+
title="Nova",
|
| 42 |
+
description="Powered by dev pro solution",
|
| 43 |
+
live=True, # Set live to True for real-time feedback
|
| 44 |
+
allow_flagging="never", # Disable flagging
|
| 45 |
+
css=css
|
| 46 |
+
)
|
| 47 |
+
iface.dependencies[0]['show_progress'] = "hidden"
|
| 48 |
+
iface.dependencies[2]['show_progress'] = "hidden"
|
| 49 |
+
|
| 50 |
+
# Launch the app
|
| 51 |
+
iface.launch()
|