Spaces:
Runtime error
Runtime error
Commit ·
caa0347
1
Parent(s): 3808873
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Load the tokenizer and model
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained("gpt2")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def generate_response(input_text):
|
| 11 |
+
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
| 12 |
+
generated_output = model.generate(input_ids, max_length=100, num_return_sequences=1)
|
| 13 |
+
response = tokenizer.decode(generated_output[0], skip_special_tokens=True)
|
| 14 |
+
return response
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=generate_response,
|
| 19 |
+
inputs='text',
|
| 20 |
+
outputs='text',
|
| 21 |
+
layout='vertical',
|
| 22 |
+
title='ChatGPT',
|
| 23 |
+
description='A simple chatbot powered by ChatGPT',
|
| 24 |
+
article= 'https://huggingface.co/models',
|
| 25 |
+
examples=[['Hello'], ['How are you?'], ['What is your name?']],
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
iface.launch()
|