Spaces:
Sleeping
Sleeping
Akshay Choudhari commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,10 +56,10 @@ def generate_prompts(user_input: str, history: list):
|
|
| 56 |
if not user_input.strip():
|
| 57 |
return history, history, ""
|
| 58 |
|
|
|
|
| 59 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 60 |
-
for
|
| 61 |
-
messages.append({"role": "
|
| 62 |
-
messages.append({"role": "assistant", "content": h[1]})
|
| 63 |
messages.append({"role": "user", "content": user_input})
|
| 64 |
|
| 65 |
try:
|
|
@@ -76,7 +76,7 @@ def generate_prompts(user_input: str, history: list):
|
|
| 76 |
)
|
| 77 |
raw = response.json()["choices"][0]["message"]["content"].strip()
|
| 78 |
|
| 79 |
-
# Try to extract
|
| 80 |
json_match = re.search(r'\{[\s\S]*\}', raw)
|
| 81 |
if json_match:
|
| 82 |
parsed = json.loads(json_match.group())
|
|
@@ -85,12 +85,19 @@ def generate_prompts(user_input: str, history: list):
|
|
| 85 |
else:
|
| 86 |
display = raw
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return new_history, new_history, ""
|
| 90 |
|
| 91 |
except Exception as e:
|
| 92 |
-
err = f"⚠️ Error: {str(e)}
|
| 93 |
-
new_history = history + [
|
|
|
|
|
|
|
|
|
|
| 94 |
return new_history, new_history, ""
|
| 95 |
|
| 96 |
|
|
@@ -129,24 +136,6 @@ h1 {
|
|
| 129 |
font-family: 'Space Mono', monospace;
|
| 130 |
}
|
| 131 |
|
| 132 |
-
.chatbot .message {
|
| 133 |
-
font-family: 'Space Mono', monospace !important;
|
| 134 |
-
font-size: 0.78rem !important;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
.chatbot .user {
|
| 138 |
-
background: #1a1a2e !important;
|
| 139 |
-
border: 1px solid #2d2d4e !important;
|
| 140 |
-
border-radius: 8px !important;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
.chatbot .bot {
|
| 144 |
-
background: #0d1117 !important;
|
| 145 |
-
border: 1px solid #7c3aed44 !important;
|
| 146 |
-
border-radius: 8px !important;
|
| 147 |
-
color: #c4b5fd !important;
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
textarea, input {
|
| 151 |
background: #111120 !important;
|
| 152 |
border: 1px solid #2d2d4e !important;
|
|
@@ -171,14 +160,6 @@ button.secondary {
|
|
| 171 |
color: #6b6b8a !important;
|
| 172 |
border-radius: 8px !important;
|
| 173 |
}
|
| 174 |
-
|
| 175 |
-
.examples-table td {
|
| 176 |
-
background: #111120 !important;
|
| 177 |
-
border: 1px solid #2d2d4e !important;
|
| 178 |
-
color: #a78bfa !important;
|
| 179 |
-
font-family: 'Space Mono', monospace !important;
|
| 180 |
-
font-size: 0.75rem !important;
|
| 181 |
-
}
|
| 182 |
"""
|
| 183 |
|
| 184 |
with gr.Blocks(title="PromptForge") as demo:
|
|
@@ -187,11 +168,12 @@ with gr.Blocks(title="PromptForge") as demo:
|
|
| 187 |
<p class="subtitle">simple words → detailed JSON image & video prompts</p>
|
| 188 |
""")
|
| 189 |
|
|
|
|
| 190 |
chatbot = gr.Chatbot(
|
| 191 |
label="",
|
| 192 |
height=480,
|
| 193 |
show_label=False,
|
| 194 |
-
|
| 195 |
)
|
| 196 |
|
| 197 |
state = gr.State([])
|
|
|
|
| 56 |
if not user_input.strip():
|
| 57 |
return history, history, ""
|
| 58 |
|
| 59 |
+
# Build messages for llama.cpp — extract from role/content history
|
| 60 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 61 |
+
for msg in history:
|
| 62 |
+
messages.append({"role": msg["role"], "content": msg["content"]})
|
|
|
|
| 63 |
messages.append({"role": "user", "content": user_input})
|
| 64 |
|
| 65 |
try:
|
|
|
|
| 76 |
)
|
| 77 |
raw = response.json()["choices"][0]["message"]["content"].strip()
|
| 78 |
|
| 79 |
+
# Try to extract and pretty-print JSON
|
| 80 |
json_match = re.search(r'\{[\s\S]*\}', raw)
|
| 81 |
if json_match:
|
| 82 |
parsed = json.loads(json_match.group())
|
|
|
|
| 85 |
else:
|
| 86 |
display = raw
|
| 87 |
|
| 88 |
+
# Gradio 6 messages format: list of {"role": ..., "content": ...}
|
| 89 |
+
new_history = history + [
|
| 90 |
+
{"role": "user", "content": user_input},
|
| 91 |
+
{"role": "assistant", "content": display},
|
| 92 |
+
]
|
| 93 |
return new_history, new_history, ""
|
| 94 |
|
| 95 |
except Exception as e:
|
| 96 |
+
err = f"⚠️ Error: {str(e)}"
|
| 97 |
+
new_history = history + [
|
| 98 |
+
{"role": "user", "content": user_input},
|
| 99 |
+
{"role": "assistant", "content": err},
|
| 100 |
+
]
|
| 101 |
return new_history, new_history, ""
|
| 102 |
|
| 103 |
|
|
|
|
| 136 |
font-family: 'Space Mono', monospace;
|
| 137 |
}
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
textarea, input {
|
| 140 |
background: #111120 !important;
|
| 141 |
border: 1px solid #2d2d4e !important;
|
|
|
|
| 160 |
color: #6b6b8a !important;
|
| 161 |
border-radius: 8px !important;
|
| 162 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
"""
|
| 164 |
|
| 165 |
with gr.Blocks(title="PromptForge") as demo:
|
|
|
|
| 168 |
<p class="subtitle">simple words → detailed JSON image & video prompts</p>
|
| 169 |
""")
|
| 170 |
|
| 171 |
+
# Gradio 6: type="messages" uses role/content dicts
|
| 172 |
chatbot = gr.Chatbot(
|
| 173 |
label="",
|
| 174 |
height=480,
|
| 175 |
show_label=False,
|
| 176 |
+
type="messages",
|
| 177 |
)
|
| 178 |
|
| 179 |
state = gr.State([])
|