Spaces:
Running
Running
Update
Browse files
app.py
CHANGED
|
@@ -1,46 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
import os
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
load_dotenv()
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
-
def respond(
|
| 14 |
-
message
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
if val[1]:
|
| 27 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 28 |
-
|
| 29 |
-
messages.append({"role": "user", "content": message})
|
| 30 |
-
|
| 31 |
-
response = ""
|
| 32 |
-
|
| 33 |
-
for message in client.chat_completion(
|
| 34 |
-
messages,
|
| 35 |
-
max_tokens=max_tokens,
|
| 36 |
-
stream=True,
|
| 37 |
temperature=temperature,
|
| 38 |
top_p=top_p,
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
|
|
|
|
| 44 |
system_message = gr.State(
|
| 45 |
"I am Bilguun, a third year software engineering student at McGill University and the founder of VentureCircle. "
|
| 46 |
"VentureCircle is based in Montreal. "
|
|
@@ -49,6 +47,7 @@ system_message = gr.State(
|
|
| 49 |
"LaunchPad is a friendly AI assistant designed to provide useful and supportive guidance for starting and growing a startup."
|
| 50 |
)
|
| 51 |
|
|
|
|
| 52 |
demo = gr.ChatInterface(
|
| 53 |
fn=respond,
|
| 54 |
additional_inputs=[
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import os
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
load_dotenv()
|
| 7 |
|
| 8 |
+
# Load model from Hugging Face Hub
|
| 9 |
+
model_id = "VentureCircle/LaunchPad"
|
| 10 |
+
token = os.getenv("huggingface_token")
|
| 11 |
+
|
| 12 |
+
generator = pipeline(
|
| 13 |
+
"text-generation",
|
| 14 |
+
model=model_id,
|
| 15 |
+
tokenizer=model_id,
|
| 16 |
+
token=token
|
| 17 |
)
|
| 18 |
|
| 19 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 20 |
+
# Combine chat history and message into a single prompt
|
| 21 |
+
chat_prompt = system_message + "\n\n"
|
| 22 |
+
for user, assistant in history:
|
| 23 |
+
if user:
|
| 24 |
+
chat_prompt += f"User: {user}\n"
|
| 25 |
+
if assistant:
|
| 26 |
+
chat_prompt += f"LaunchPad: {assistant}\n"
|
| 27 |
+
chat_prompt += f"User: {message}\nLaunchPad:"
|
| 28 |
+
|
| 29 |
+
output = generator(
|
| 30 |
+
chat_prompt,
|
| 31 |
+
max_new_tokens=max_tokens,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
temperature=temperature,
|
| 33 |
top_p=top_p,
|
| 34 |
+
do_sample=True
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Extract response only (after "LaunchPad:")
|
| 38 |
+
response_text = output[0]["generated_text"].split("LaunchPad:")[-1].strip()
|
| 39 |
+
return response_text
|
| 40 |
|
| 41 |
+
# System message configuration
|
| 42 |
system_message = gr.State(
|
| 43 |
"I am Bilguun, a third year software engineering student at McGill University and the founder of VentureCircle. "
|
| 44 |
"VentureCircle is based in Montreal. "
|
|
|
|
| 47 |
"LaunchPad is a friendly AI assistant designed to provide useful and supportive guidance for starting and growing a startup."
|
| 48 |
)
|
| 49 |
|
| 50 |
+
# Gradio interface
|
| 51 |
demo = gr.ChatInterface(
|
| 52 |
fn=respond,
|
| 53 |
additional_inputs=[
|