Spaces:
Runtime error
Runtime error
update
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
+
|
| 6 |
+
model_name = "TheFinAI/Fin-o1-14B"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@spaces.GPU
|
| 12 |
+
def chat(input_text):
|
| 13 |
+
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
|
| 14 |
+
output = model.generate(**inputs, max_new_tokens=200)
|
| 15 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 16 |
+
return response
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
fn=chat,
|
| 21 |
+
inputs=gr.Textbox(label="输入问题", placeholder="例如: What is the ?"),
|
| 22 |
+
outputs=gr.Textbox(label="回答"),
|
| 23 |
+
title="FinChatBox",
|
| 24 |
+
description="使用 TheFinAI 模型进行对话"
|
| 25 |
+
)
|
| 26 |
+
demo.launch()
|