Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,26 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
{"role": "user", "content": "Hello!"},
|
| 5 |
-
]
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# Load the model and tokenizer from Hugging Face
|
| 6 |
+
model_name = "fahadMizan/chatbot"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# Define the chatbot function
|
| 11 |
+
def chatbot(input_text):
|
| 12 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 13 |
+
outputs = model.generate(inputs["input_ids"], max_length=100)
|
| 14 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
+
return response
|
| 16 |
+
|
| 17 |
+
# Create the Gradio interface
|
| 18 |
+
iface = gr.Interface(fn=chatbot,
|
| 19 |
+
inputs="text",
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="Fahad Chatbot",
|
| 22 |
+
description="A chatbot using the 'fahadMizan/chatbot' model from Hugging Face.")
|
| 23 |
+
|
| 24 |
+
# Launch the app
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
iface.launch()
|