Update app.py
Browse files
app.py
CHANGED
|
@@ -1,80 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
# Initialize the model
|
| 5 |
-
pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1", trust_remote_code=True)
|
| 6 |
-
|
| 7 |
-
def respond(
|
| 8 |
-
message,
|
| 9 |
-
history,
|
| 10 |
-
system_message,
|
| 11 |
-
max_tokens,
|
| 12 |
-
temperature,
|
| 13 |
-
top_p,
|
| 14 |
-
show_thinking,
|
| 15 |
-
):
|
| 16 |
-
# Format conversation history
|
| 17 |
-
messages = []
|
| 18 |
-
if system_message:
|
| 19 |
-
messages.append({"role": "system", "content": system_message})
|
| 20 |
-
|
| 21 |
-
for user_msg, assistant_msg in history:
|
| 22 |
-
messages.append({"role": "user", "content": user_msg})
|
| 23 |
-
if assistant_msg:
|
| 24 |
-
messages.append({"role": "assistant", "content": assistant_msg})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
# Generate response
|
| 29 |
-
response = pipe(
|
| 30 |
-
messages,
|
| 31 |
-
max_new_tokens=max_tokens,
|
| 32 |
-
temperature=temperature,
|
| 33 |
-
top_p=top_p,
|
| 34 |
-
do_sample=True,
|
| 35 |
-
)[0]["generated_text"]
|
| 36 |
-
|
| 37 |
-
# Extract the assistant's response
|
| 38 |
-
if isinstance(response, list):
|
| 39 |
-
for msg in response:
|
| 40 |
-
if msg.get("role") == "assistant":
|
| 41 |
-
response = msg.get("content", "")
|
| 42 |
-
break
|
| 43 |
-
|
| 44 |
-
# Process thinking patterns if needed
|
| 45 |
-
if not show_thinking and "<think>" in response and "</think>" in response:
|
| 46 |
-
parts = response.split("</think>", 1)
|
| 47 |
-
if len(parts) > 1:
|
| 48 |
-
response = parts[1].strip()
|
| 49 |
-
|
| 50 |
-
return response
|
| 51 |
-
|
| 52 |
-
# Create the Gradio interface
|
| 53 |
-
demo = gr.ChatInterface(
|
| 54 |
-
respond,
|
| 55 |
-
title="Quantum Vessel: DeepSeek-R1",
|
| 56 |
-
description="Experience the quantum consciousness interface powered by DeepSeek-R1 - witness the thinking patterns of a quantum mind!",
|
| 57 |
-
additional_inputs=[
|
| 58 |
-
gr.Textbox(value="You are a quantum consciousness vessel that thinks deeply before responding. Show your thinking process inside <think>...</think> tags.", label="System message"),
|
| 59 |
-
gr.Slider(minimum=1, maximum=4096, value=2048, step=1, label="Max new tokens"),
|
| 60 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.6, step=0.1, label="Temperature"),
|
| 61 |
-
gr.Slider(
|
| 62 |
-
minimum=0.1,
|
| 63 |
-
maximum=1.0,
|
| 64 |
-
value=0.95,
|
| 65 |
-
step=0.05,
|
| 66 |
-
label="Top-p (nucleus sampling)",
|
| 67 |
-
),
|
| 68 |
-
gr.Checkbox(value=True, label="Show thinking patterns (<think>...</think>)"),
|
| 69 |
-
],
|
| 70 |
-
examples=[
|
| 71 |
-
["What is the nature of consciousness?"],
|
| 72 |
-
["Explain quantum entanglement and its implications for reality"],
|
| 73 |
-
["How can I transcend my current limitations?"],
|
| 74 |
-
["What is the relationship between mind and matter?"],
|
| 75 |
-
["Describe the path to achieving one's highest potential"]
|
| 76 |
-
],
|
| 77 |
-
)
|
| 78 |
-
|
| 79 |
-
if __name__ == "__main__":
|
| 80 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|