Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
-
import tiktoken
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 6 |
from threading import Thread
|
| 7 |
|
|
@@ -25,10 +24,6 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 25 |
print("Model loaded successfully.")
|
| 26 |
|
| 27 |
def generate_code(prompt, history):
|
| 28 |
-
# Gradio 6.x uses the 'messages' format by default
|
| 29 |
-
# history will look like: [{"role": "user", "content": "..."}, {"role": "assistant", "content": "..."}]
|
| 30 |
-
|
| 31 |
-
# Prepend existing history to the current prompt
|
| 32 |
messages = history + [{"role": "user", "content": prompt}]
|
| 33 |
|
| 34 |
# Prepare inputs using the model's chat template
|
|
@@ -63,7 +58,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
|
| 63 |
|
| 64 |
# In Gradio 6, type="messages" is the standard for the chatbot component
|
| 65 |
chatbot = gr.Chatbot(height=500, show_copy_button=True, type="messages")
|
| 66 |
-
|
| 67 |
with gr.Row():
|
| 68 |
msg = gr.Textbox(
|
| 69 |
placeholder="E.g., Create a responsive navigation bar with CSS...",
|
|
@@ -71,12 +65,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
|
| 71 |
scale=9
|
| 72 |
)
|
| 73 |
submit = gr.Button("Build", variant="primary", scale=1)
|
| 74 |
-
|
| 75 |
-
# Wire up the events
|
| 76 |
msg.submit(generate_code, [msg, chatbot], [chatbot])
|
| 77 |
submit.click(generate_code, [msg, chatbot], [chatbot])
|
| 78 |
-
|
| 79 |
-
# Clear the input box after submission
|
| 80 |
msg.submit(lambda: "", None, [msg])
|
| 81 |
submit.click(lambda: "", None, [msg])
|
| 82 |
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
|
|
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 5 |
from threading import Thread
|
| 6 |
|
|
|
|
| 24 |
print("Model loaded successfully.")
|
| 25 |
|
| 26 |
def generate_code(prompt, history):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
messages = history + [{"role": "user", "content": prompt}]
|
| 28 |
|
| 29 |
# Prepare inputs using the model's chat template
|
|
|
|
| 58 |
|
| 59 |
# In Gradio 6, type="messages" is the standard for the chatbot component
|
| 60 |
chatbot = gr.Chatbot(height=500, show_copy_button=True, type="messages")
|
|
|
|
| 61 |
with gr.Row():
|
| 62 |
msg = gr.Textbox(
|
| 63 |
placeholder="E.g., Create a responsive navigation bar with CSS...",
|
|
|
|
| 65 |
scale=9
|
| 66 |
)
|
| 67 |
submit = gr.Button("Build", variant="primary", scale=1)
|
|
|
|
|
|
|
| 68 |
msg.submit(generate_code, [msg, chatbot], [chatbot])
|
| 69 |
submit.click(generate_code, [msg, chatbot], [chatbot])
|
|
|
|
|
|
|
| 70 |
msg.submit(lambda: "", None, [msg])
|
| 71 |
submit.click(lambda: "", None, [msg])
|
| 72 |
|