Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,81 +1,60 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
-
import torch
|
4 |
-
from TTS.api import TTS
|
5 |
import os
|
6 |
import subprocess
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
response = ""
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
chatbot = gr.Chatbot(type="messages") # β
Fix deprecated type warning
|
66 |
-
msg = gr.Textbox(label="User Input")
|
67 |
-
|
68 |
-
system_msg = gr.Textbox(value="You are a friendly Chatbot.", label="System Message")
|
69 |
-
max_tokens = gr.Slider(1, 2048, value=512, step=1, label="Max Tokens")
|
70 |
-
temperature = gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature")
|
71 |
-
top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p (Nucleus Sampling)")
|
72 |
-
|
73 |
-
tts_audio = gr.Audio(type="filepath", label="TTS Output")
|
74 |
-
rvc_audio = gr.Audio(type="filepath", label="RVC ZeldaBotW Voice")
|
75 |
-
|
76 |
-
def chat_fn(message, history):
|
77 |
-
return respond(message, history, system_msg.value, max_tokens.value, temperature.value, top_p.value)
|
78 |
-
|
79 |
-
msg.submit(chat_fn, inputs=[msg, chatbot], outputs=[chatbot, tts_audio, rvc_audio])
|
80 |
-
|
81 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import subprocess
|
3 |
+
import gradio as gr
|
4 |
+
import ollama
|
5 |
+
|
6 |
+
# Ensure Ollama is installed
|
7 |
+
def install_ollama():
|
8 |
+
try:
|
9 |
+
subprocess.run(["ollama", "--version"], check=True)
|
10 |
+
print("β
Ollama is already installed.")
|
11 |
+
except FileNotFoundError:
|
12 |
+
print("π Installing Ollama...")
|
13 |
+
subprocess.run(["curl", "-fsSL", "https://ollama.com/install.sh", "|", "sh"], shell=True, check=True)
|
14 |
+
print("β
Ollama installed successfully!")
|
15 |
+
|
16 |
+
# Start Ollama if it's not running
|
17 |
+
def start_ollama():
|
18 |
+
try:
|
19 |
+
subprocess.run(["pgrep", "-f", "ollama"], check=True)
|
20 |
+
print("β
Ollama is already running.")
|
21 |
+
except subprocess.CalledProcessError:
|
22 |
+
print("π Starting Ollama server...")
|
23 |
+
subprocess.Popen(["ollama", "serve"])
|
24 |
+
print("β
Ollama started.")
|
25 |
+
|
26 |
+
# Ensure model is downloaded to models/ folder
|
27 |
+
MODEL_NAME = "deepseek-llm-7b"
|
28 |
+
MODEL_PATH = f"models/{MODEL_NAME}"
|
29 |
+
|
30 |
+
def download_model():
|
31 |
+
if not os.path.exists(MODEL_PATH):
|
32 |
+
print(f"π Downloading model: {MODEL_NAME} to {MODEL_PATH} ...")
|
33 |
+
os.makedirs("models", exist_ok=True)
|
34 |
+
subprocess.run(["ollama", "pull", f"deepseek/{MODEL_NAME}"], check=True)
|
35 |
+
print(f"β
Model downloaded to {MODEL_PATH}.")
|
36 |
+
else:
|
37 |
+
print(f"β
Model {MODEL_NAME} already exists.")
|
38 |
+
|
39 |
+
# Generate AI response using Ollama
|
40 |
+
def chat_response(user_input):
|
41 |
+
response = ollama.chat(model=MODEL_NAME, messages=[{"role": "user", "content": user_input}])
|
42 |
+
return response['message']['content']
|
43 |
+
|
44 |
+
# Run setup
|
45 |
+
install_ollama()
|
46 |
+
start_ollama()
|
47 |
+
download_model()
|
48 |
+
|
49 |
+
# Create Gradio Interface
|
50 |
+
iface = gr.Interface(
|
51 |
+
fn=chat_response,
|
52 |
+
inputs="text",
|
53 |
+
outputs="text",
|
54 |
+
title="DeepSeek ChatBot (Ollama)",
|
55 |
+
description="Chat with DeepSeek LLM 7B using Ollama."
|
56 |
+
)
|
57 |
+
|
58 |
+
# Launch Gradio App
|
59 |
+
if __name__ == "__main__":
|
60 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|