added logs along the way - debugging
Browse files
app.py
CHANGED
|
@@ -1,19 +1,45 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
#from transformers import pipeline
|
| 3 |
-
#from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
|
|
|
|
|
|
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("kolbeins/model")
|
| 7 |
-
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def chat(input_txt):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
demo = gr.Interface(fn=chat, inputs="text", outputs="text")
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
|
| 4 |
+
# Load the tokenizer and model
|
| 5 |
+
print("Loading tokenizer...")
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("kolbeins/model")
|
| 7 |
+
print("Tokenizer loaded.")
|
| 8 |
|
| 9 |
+
print("Loading model...")
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained("kolbeins/model")
|
| 11 |
+
print("Model loaded.")
|
| 12 |
|
| 13 |
def chat(input_txt):
|
| 14 |
+
"""
|
| 15 |
+
Function to generate a response using the model for the given input text.
|
| 16 |
+
"""
|
| 17 |
+
try:
|
| 18 |
+
print("Tokenizing input...")
|
| 19 |
+
# Tokenizing the input text, making sure to add special tokens if necessary
|
| 20 |
+
inputs = tokenizer(input_txt, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 21 |
+
print(f"Tokenized inputs: {inputs}")
|
| 22 |
|
| 23 |
+
print("Generating output...")
|
| 24 |
+
# Generate the output using the model
|
| 25 |
+
outputs = model.generate(**inputs)
|
| 26 |
+
print(f"Generated output: {outputs}")
|
| 27 |
|
| 28 |
+
print("Decoding output...")
|
| 29 |
+
# Decode the output (the model generates token IDs, so we need to decode them back to text)
|
| 30 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 31 |
+
print(f"Decoded response: {response}")
|
| 32 |
+
|
| 33 |
+
# Return the generated response
|
| 34 |
+
return response
|
| 35 |
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"Error during inference: {e}")
|
| 38 |
+
return f"Error: {e}"
|
| 39 |
+
|
| 40 |
+
# Define the Gradio interface for the chatbot
|
| 41 |
demo = gr.Interface(fn=chat, inputs="text", outputs="text")
|
| 42 |
+
|
| 43 |
+
# Launch the interface
|
| 44 |
+
print("Launching Gradio interface...")
|
| 45 |
+
demo.launch()
|