Spaces:
Build error
Build error
Ashhar commited on
Commit ·
b24e527
1
Parent(s): e4f4c98
reduce flickering
Browse files
app.py
CHANGED
|
@@ -12,7 +12,8 @@ client = Groq(api_key=os.getenv('GROQ_API_KEY'))
|
|
| 12 |
|
| 13 |
SYSTEM_PROMPT = """
|
| 14 |
You complete every sentence in a very interesting way. Use emojis wherever possible.
|
| 15 |
-
Preserve everything in the user prompt and append to it to complete the sentence
|
|
|
|
| 16 |
|
| 17 |
eg:
|
| 18 |
Q. What's my
|
|
@@ -38,7 +39,6 @@ A. I love to eat eggs for breakfast! 🧦🍳 Eggs are healthy as well as tasty
|
|
| 38 |
|
| 39 |
"""
|
| 40 |
|
| 41 |
-
lastResponse = ""
|
| 42 |
ipAddress = ""
|
| 43 |
|
| 44 |
|
|
@@ -64,7 +64,7 @@ def autocomplete(text):
|
|
| 64 |
|
| 65 |
if text != "":
|
| 66 |
if text[-1] != " ":
|
| 67 |
-
yield lastResponse
|
| 68 |
return
|
| 69 |
|
| 70 |
pprint(f"{text=}")
|
|
@@ -92,9 +92,9 @@ def autocomplete(text):
|
|
| 92 |
partialMessage = partialMessage + chunk.choices[0].delta.content
|
| 93 |
yield partialMessage
|
| 94 |
pprint(f"{partialMessage=}")
|
| 95 |
-
lastResponse = partialMessage
|
| 96 |
-
else:
|
| 97 |
-
|
| 98 |
|
| 99 |
|
| 100 |
css = """
|
|
@@ -103,35 +103,67 @@ css = """
|
|
| 103 |
# }
|
| 104 |
"""
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
)
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
| 131 |
fn=lambda x: x,
|
| 132 |
-
inputs=
|
| 133 |
-
outputs=
|
| 134 |
)
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
# Launch the app
|
| 137 |
demo.launch(debug=True)
|
|
|
|
| 12 |
|
| 13 |
SYSTEM_PROMPT = """
|
| 14 |
You complete every sentence in a very interesting way. Use emojis wherever possible.
|
| 15 |
+
Preserve everything in the user prompt and append to it to complete the ongoing sentence.
|
| 16 |
+
Don't add additional sentences.
|
| 17 |
|
| 18 |
eg:
|
| 19 |
Q. What's my
|
|
|
|
| 39 |
|
| 40 |
"""
|
| 41 |
|
|
|
|
| 42 |
ipAddress = ""
|
| 43 |
|
| 44 |
|
|
|
|
| 64 |
|
| 65 |
if text != "":
|
| 66 |
if text[-1] != " ":
|
| 67 |
+
# yield lastResponse
|
| 68 |
return
|
| 69 |
|
| 70 |
pprint(f"{text=}")
|
|
|
|
| 92 |
partialMessage = partialMessage + chunk.choices[0].delta.content
|
| 93 |
yield partialMessage
|
| 94 |
pprint(f"{partialMessage=}")
|
| 95 |
+
# lastResponse = partialMessage
|
| 96 |
+
# else:
|
| 97 |
+
# lastResponse = ""
|
| 98 |
|
| 99 |
|
| 100 |
css = """
|
|
|
|
| 103 |
# }
|
| 104 |
"""
|
| 105 |
|
| 106 |
+
with gr.Blocks(css=css, title="Create interesting sentences on the fly ✈") as demo:
|
| 107 |
+
gr.Markdown("# Create interesting sentences on the fly ✈")
|
| 108 |
+
gr.Markdown("Powered by Groq & Llama 3.1")
|
| 109 |
+
|
| 110 |
+
with gr.Row():
|
| 111 |
+
input_box = gr.Textbox(
|
| 112 |
+
lines=2,
|
| 113 |
+
placeholder="Start typing ...",
|
| 114 |
+
label="Input Sentence",
|
| 115 |
+
)
|
| 116 |
+
output_box = gr.Markdown(
|
| 117 |
+
label="Output Sentence"
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
copy_button = gr.Button("Use Output", variant="primary")
|
| 121 |
+
|
| 122 |
+
input_box.change(
|
| 123 |
+
fn=autocomplete,
|
| 124 |
+
inputs=input_box,
|
| 125 |
+
outputs=output_box,
|
| 126 |
+
show_progress="hidden",
|
| 127 |
+
api_name=None,
|
| 128 |
+
queue=True,
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
copy_button.click(
|
| 132 |
fn=lambda x: x,
|
| 133 |
+
inputs=output_box,
|
| 134 |
+
outputs=input_box,
|
| 135 |
)
|
| 136 |
|
| 137 |
+
|
| 138 |
+
# inputBox = gr.Textbox(
|
| 139 |
+
# lines=2,
|
| 140 |
+
# placeholder="Start typing ...",
|
| 141 |
+
# label="Input Sentence",
|
| 142 |
+
# )
|
| 143 |
+
# outputBox = gr.Markdown(
|
| 144 |
+
# label="Output Sentence"
|
| 145 |
+
# )
|
| 146 |
+
|
| 147 |
+
# with gr.Interface(
|
| 148 |
+
# fn=autocomplete,
|
| 149 |
+
# inputs=inputBox,
|
| 150 |
+
# outputs=outputBox,
|
| 151 |
+
# title="Create interesting sentences on the fly ✈",
|
| 152 |
+
# description="Powered by Groq & Llama 3.1",
|
| 153 |
+
# live=True, # Set live to True for real-time feedback
|
| 154 |
+
# allow_flagging="never", # Disable flagging
|
| 155 |
+
# css=css
|
| 156 |
+
# ) as demo:
|
| 157 |
+
# # demo.load(__attachIp, None, None)
|
| 158 |
+
# copyButton = gr.Button(
|
| 159 |
+
# "Use Output",
|
| 160 |
+
# elem_id="copy-button",
|
| 161 |
+
# variant="primary"
|
| 162 |
+
# ).click(
|
| 163 |
+
# fn=lambda x: x,
|
| 164 |
+
# inputs=outputBox,
|
| 165 |
+
# outputs=inputBox,
|
| 166 |
+
# )
|
| 167 |
+
|
| 168 |
# Launch the app
|
| 169 |
demo.launch(debug=True)
|