Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,14 +12,22 @@ def chat_engine(message, history, model_choice):
|
|
| 12 |
pipe = pipeline("text-generation", model=MODELS[model_choice])
|
| 13 |
|
| 14 |
prompt = f"System: You are {model_choice}, the flagship AI of Zakomako4567. Use clean code.\n"
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
prompt += f"User: {message}\nAI:"
|
| 18 |
|
| 19 |
res = pipe(prompt, max_new_tokens=512, do_sample=True, temperature=0.7)[0]['generated_text']
|
| 20 |
return res.split("AI:")[-1].strip()
|
| 21 |
|
| 22 |
-
#
|
| 23 |
custom_css = """
|
| 24 |
footer {visibility: hidden}
|
| 25 |
.gradio-container { background: #050505 !important; color: white !important; }
|
|
@@ -36,13 +44,11 @@ footer {visibility: hidden}
|
|
| 36 |
"""
|
| 37 |
|
| 38 |
# 2. Building the Interface
|
| 39 |
-
# We removed theme/css from here to satisfy the Gradio 6.0 warning
|
| 40 |
with gr.Blocks() as demo:
|
| 41 |
|
| 42 |
-
# Replaced gr.Div with gr.Column to avoid the AttributeError
|
| 43 |
with gr.Column(elem_id="title-header"):
|
| 44 |
gr.Markdown(f"# 🚀 ZewAI 3 by @Zakomako4567")
|
| 45 |
-
gr.Markdown("The
|
| 46 |
|
| 47 |
with gr.Row():
|
| 48 |
# --- LEFT SIDEBAR ---
|
|
@@ -66,17 +72,18 @@ with gr.Blocks() as demo:
|
|
| 66 |
|
| 67 |
# --- RIGHT MAIN ---
|
| 68 |
with gr.Column(scale=4):
|
|
|
|
| 69 |
gr.ChatInterface(
|
| 70 |
fn=chat_engine,
|
| 71 |
additional_inputs=[model_dropdown],
|
| 72 |
-
type="messages",
|
| 73 |
examples=["Build a Python web scraper", "Explain ZewML logic"],
|
| 74 |
)
|
| 75 |
|
| 76 |
-
#
|
| 77 |
if __name__ == "__main__":
|
| 78 |
demo.launch(
|
| 79 |
css=custom_css,
|
| 80 |
theme=gr.themes.Default(primary_hue="blue", secondary_hue="slate")
|
| 81 |
)
|
| 82 |
|
|
|
|
|
|
| 12 |
pipe = pipeline("text-generation", model=MODELS[model_choice])
|
| 13 |
|
| 14 |
prompt = f"System: You are {model_choice}, the flagship AI of Zakomako4567. Use clean code.\n"
|
| 15 |
+
|
| 16 |
+
# Updated history handling for Gradio 6.0 compatibility
|
| 17 |
+
for turn in history:
|
| 18 |
+
user_msg = turn['role'] == 'user'
|
| 19 |
+
content = turn['content']
|
| 20 |
+
if user_msg:
|
| 21 |
+
prompt += f"User: {content}\n"
|
| 22 |
+
else:
|
| 23 |
+
prompt += f"AI: {content}\n"
|
| 24 |
+
|
| 25 |
prompt += f"User: {message}\nAI:"
|
| 26 |
|
| 27 |
res = pipe(prompt, max_new_tokens=512, do_sample=True, temperature=0.7)[0]['generated_text']
|
| 28 |
return res.split("AI:")[-1].strip()
|
| 29 |
|
| 30 |
+
# Premium CSS Styling
|
| 31 |
custom_css = """
|
| 32 |
footer {visibility: hidden}
|
| 33 |
.gradio-container { background: #050505 !important; color: white !important; }
|
|
|
|
| 44 |
"""
|
| 45 |
|
| 46 |
# 2. Building the Interface
|
|
|
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
|
|
|
|
| 49 |
with gr.Column(elem_id="title-header"):
|
| 50 |
gr.Markdown(f"# 🚀 ZewAI 3 by @Zakomako4567")
|
| 51 |
+
gr.Markdown("The flagship coding AI for the ZewpolOS ecosystem.")
|
| 52 |
|
| 53 |
with gr.Row():
|
| 54 |
# --- LEFT SIDEBAR ---
|
|
|
|
| 72 |
|
| 73 |
# --- RIGHT MAIN ---
|
| 74 |
with gr.Column(scale=4):
|
| 75 |
+
# Removed 'type="messages"' to fix the TypeError
|
| 76 |
gr.ChatInterface(
|
| 77 |
fn=chat_engine,
|
| 78 |
additional_inputs=[model_dropdown],
|
|
|
|
| 79 |
examples=["Build a Python web scraper", "Explain ZewML logic"],
|
| 80 |
)
|
| 81 |
|
| 82 |
+
# Apply styling during launch
|
| 83 |
if __name__ == "__main__":
|
| 84 |
demo.launch(
|
| 85 |
css=custom_css,
|
| 86 |
theme=gr.themes.Default(primary_hue="blue", secondary_hue="slate")
|
| 87 |
)
|
| 88 |
|
| 89 |
+
|