Trigger82 commited on
Commit
3fcb18f
Β·
verified Β·
1 Parent(s): 91de079

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -27,7 +27,7 @@ def enhance_response(resp, message):
27
  def chat(user_input, history):
28
  context = format_context(history) + f"You: {user_input}\n𝕴 𝖆𝖒 π–π–Žπ–’:"
29
  inputs = tokenizer.encode(context, return_tensors="pt", truncation=True, max_length=1024)
30
-
31
  outputs = model.generate(
32
  inputs,
33
  max_new_tokens=50,
@@ -40,17 +40,12 @@ def chat(user_input, history):
40
  full_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
41
  response = full_text.split("𝕴 𝖆𝖒 π–π–Žπ–’:")[-1].split("\nYou:")[0].strip()
42
  response = enhance_response(response, user_input)
43
-
44
- history.append((user_input, response))
45
- return history # Return just the updated chat history
46
 
47
- with gr.Blocks() as demo:
48
- gr.Markdown("# 𝕴 𝖆𝖒 π–π–Žπ–’\n*Smooth β€’ Chill β€’ Emotional*")
49
- chatbot = gr.Chatbot(height=400, type="messages", label="Chat")
50
- msg = gr.Textbox(placeholder="Type something…", show_label=False)
51
- state = gr.State([])
52
 
53
- msg.submit(chat, [msg, state], [chatbot, state])
54
- gr.Button("Reset").click(lambda: [], None, [chatbot, state])
55
 
56
- demo.launch(server_name="0.0.0.0", server_port=7860, enable_api=True)
 
 
27
  def chat(user_input, history):
28
  context = format_context(history) + f"You: {user_input}\n𝕴 𝖆𝖒 π–π–Žπ–’:"
29
  inputs = tokenizer.encode(context, return_tensors="pt", truncation=True, max_length=1024)
30
+
31
  outputs = model.generate(
32
  inputs,
33
  max_new_tokens=50,
 
40
  full_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
41
  response = full_text.split("𝕴 𝖆𝖒 π–π–Žπ–’:")[-1].split("\nYou:")[0].strip()
42
  response = enhance_response(response, user_input)
 
 
 
43
 
44
+ history.append((user_input, response))
45
+ return history
 
 
 
46
 
47
+ # Create the Gradio Interface
48
+ demo = gr.Interface(fn=chat, inputs=["text", "state"], outputs="state")
49
 
50
+ # Launch the app
51
+ demo.launch()