Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
formatted_input = f"<s>[INST] {user_message} [/INST]"
|
| 9 |
-
response = chat_model(formatted_input, max_length=512)
|
| 10 |
-
response_text = response[0]['generated_text']
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
response_parts = response_text.split("[/INST]")
|
| 15 |
if len(response_parts) > 1:
|
| 16 |
-
ai_response = response_parts[1].
|
| 17 |
else:
|
| 18 |
ai_response = "Sorry, I couldn't process that message."
|
| 19 |
|
| 20 |
return ai_response
|
| 21 |
|
| 22 |
gradio_app = gr.Interface(
|
| 23 |
-
fn=
|
| 24 |
-
inputs=gr.Textbox(lines=2, placeholder="
|
| 25 |
outputs=gr.Textbox(),
|
| 26 |
-
title="Call of Cthulhu
|
| 27 |
-
description="
|
| 28 |
)
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
gradio_app.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 3 |
|
| 4 |
+
# Replace 'your_model_name' with the actual name or path of your model
|
| 5 |
+
model_name = 'your_model_name'
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
+
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
def generate_response(user_input):
|
| 12 |
+
formatted_input = f"<s>[INST] {user_input} [/INST]"
|
| 13 |
+
result = pipe(formatted_input)
|
| 14 |
+
response_text = result[0]['generated_text']
|
| 15 |
+
|
| 16 |
+
# Extracting the AI response part, assuming it follows a specific format after [/INST]
|
| 17 |
response_parts = response_text.split("[/INST]")
|
| 18 |
if len(response_parts) > 1:
|
| 19 |
+
ai_response = response_parts[1].split("</s>")[0].strip() # Assuming the response ends with </s>
|
| 20 |
else:
|
| 21 |
ai_response = "Sorry, I couldn't process that message."
|
| 22 |
|
| 23 |
return ai_response
|
| 24 |
|
| 25 |
gradio_app = gr.Interface(
|
| 26 |
+
fn=generate_response,
|
| 27 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your message here..."),
|
| 28 |
outputs=gr.Textbox(),
|
| 29 |
+
title="Call of Cthulhu Chatbot",
|
| 30 |
+
description="Interact with the Call of Cthulhu Keeper. Type your actions or questions."
|
| 31 |
)
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
gradio_app.launch()
|
| 35 |
+
|