Spaces:
Runtime error
Runtime error
Create CatGPT.py
Browse files
CatGPT.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
class CatGPT:
|
| 5 |
+
def __init__(self, model_name="OrionStarAI/Orion-14B"):
|
| 6 |
+
self.model_name = model_name
|
| 7 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
def generate(self, prompt, max_length=100):
|
| 11 |
+
inputs = self.tokenizer(prompt, return_tensors="pt")
|
| 12 |
+
outputs = self.model.generate(inputs.input_ids, max_length=max_length)
|
| 13 |
+
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
return response
|
| 15 |
+
|
| 16 |
+
# Instantiate CatGPT
|
| 17 |
+
catgpt = CatGPT()
|
| 18 |
+
|
| 19 |
+
def catgpt_response(prompt):
|
| 20 |
+
return catgpt.generate(prompt)
|
| 21 |
+
|
| 22 |
+
# Gradio Interface
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=catgpt_response,
|
| 25 |
+
inputs="text",
|
| 26 |
+
outputs="text",
|
| 27 |
+
title="CatGPT - Orion-14B Demo",
|
| 28 |
+
description="This is a CatGPT demo using the Orion-14B model from OrionStarAI."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Launch the app
|
| 32 |
+
iface.launch()
|