Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load the model and tokenizer
|
| 6 |
+
model_name = "indonlp/cendol-llama2-7b-chat"
|
| 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 |
+
with torch.no_grad():
|
| 14 |
+
outputs = model.generate(inputs.input_ids, max_length=1000, do_sample=True)
|
| 15 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 16 |
+
return response
|
| 17 |
+
|
| 18 |
+
# Create the Gradio interface
|
| 19 |
+
interface = gr.ChatInterface(
|
| 20 |
+
fn=chatbot,
|
| 21 |
+
title="Cendol Chatnot",
|
| 22 |
+
description="Ask any coding-related questions and get helpful responses."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Launch the web UI
|
| 26 |
+
interface.launch(share=True)
|