Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
a505b42
1
Parent(s):
87accae
session state
Browse files
app.py
CHANGED
|
@@ -2,10 +2,8 @@ import spaces
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
import subprocess
|
| 5 |
-
import numpy as np
|
| 6 |
import requests
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
# Function to start the ochat server
|
| 11 |
@spaces.GPU
|
|
@@ -45,28 +43,24 @@ def chat_with_ochat(message):
|
|
| 45 |
except requests.RequestException as e:
|
| 46 |
return f"Error: {e}"
|
| 47 |
|
| 48 |
-
|
| 49 |
-
chat_history = []
|
| 50 |
-
|
| 51 |
-
# Create a Gradio Blocks interface
|
| 52 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 53 |
gr.Markdown("## vLLM OpenChat-3.5 Interface")
|
| 54 |
gr.Markdown("Run on your own machine using this command: ```docker run -it -p 7860:7860 --platform=linux/amd64 --gpus all \
|
| 55 |
-
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
input_text = gr.Textbox(label="Your Message", placeholder="Type your message here")
|
| 59 |
submit_button = gr.Button("Send")
|
| 60 |
output_chat = gr.Chatbot()
|
| 61 |
|
| 62 |
-
chat_history = []
|
| 63 |
|
| 64 |
-
def update_output(input_message):
|
| 65 |
-
global chat_history
|
| 66 |
server_response = chat_with_ochat(input_message) # Server's response
|
| 67 |
chat_history.append((input_message, server_response))
|
| 68 |
return chat_history
|
| 69 |
|
| 70 |
-
submit_button.click(fn=update_output, inputs=[input_text], outputs=[output_chat])
|
| 71 |
|
| 72 |
-
app.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
import subprocess
|
|
|
|
| 5 |
import requests
|
| 6 |
+
from gradio import State
|
|
|
|
| 7 |
|
| 8 |
# Function to start the ochat server
|
| 9 |
@spaces.GPU
|
|
|
|
| 43 |
except requests.RequestException as e:
|
| 44 |
return f"Error: {e}"
|
| 45 |
|
| 46 |
+
# Create a Gradio Blocks interface with session state
|
|
|
|
|
|
|
|
|
|
| 47 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 48 |
gr.Markdown("## vLLM OpenChat-3.5 Interface")
|
| 49 |
gr.Markdown("Run on your own machine using this command: ```docker run -it -p 7860:7860 --platform=linux/amd64 --gpus all \
|
| 50 |
+
registry.hf.space/macadeliccc-openchat-3-5-chatbot:latest python app.py```")
|
| 51 |
|
| 52 |
with gr.Row():
|
| 53 |
input_text = gr.Textbox(label="Your Message", placeholder="Type your message here")
|
| 54 |
submit_button = gr.Button("Send")
|
| 55 |
output_chat = gr.Chatbot()
|
| 56 |
|
| 57 |
+
chat_history = State([]) # Session state for chat history
|
| 58 |
|
| 59 |
+
def update_output(input_message, chat_history):
|
|
|
|
| 60 |
server_response = chat_with_ochat(input_message) # Server's response
|
| 61 |
chat_history.append((input_message, server_response))
|
| 62 |
return chat_history
|
| 63 |
|
| 64 |
+
submit_button.click(fn=update_output, inputs=[input_text, chat_history], outputs=[output_chat])
|
| 65 |
|
| 66 |
+
app.launch()
|