Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
return result[0]['generated_text']
|
12 |
|
13 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
interface = gr.Interface(
|
15 |
-
fn=
|
16 |
inputs=gr.Textbox(lines=2, placeholder="Geben Sie Ihren Text hier ein..."),
|
17 |
outputs="text",
|
18 |
title="Blockchain Assistant",
|
19 |
description="Geben Sie einen Text ein, und das Modell generiert eine Fortsetzung."
|
20 |
)
|
21 |
|
|
|
22 |
if __name__ == "__main__":
|
23 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
+
from peft import PeftModel
|
5 |
|
6 |
+
# Lade Tokenizer und Basismodell
|
7 |
+
base_model_name = "togethercomputer/Mistral-7B-Instruct-v0.2"
|
8 |
+
lora_model_name = "TooKeen/neo-blockchain-assistant"
|
9 |
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
11 |
+
base_model = AutoModelForCausalLM.from_pretrained(base_model_name, device_map="auto")
|
12 |
+
model = PeftModel.from_pretrained(base_model, lora_model_name)
|
|
|
13 |
|
14 |
+
# Definiere die Vorhersagefunktion
|
15 |
+
def generate_text(prompt):
|
16 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
17 |
+
outputs = model.generate(**inputs, max_length=100)
|
18 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
|
20 |
+
# Erstelle die Gradio-Oberfläche
|
21 |
interface = gr.Interface(
|
22 |
+
fn=generate_text,
|
23 |
inputs=gr.Textbox(lines=2, placeholder="Geben Sie Ihren Text hier ein..."),
|
24 |
outputs="text",
|
25 |
title="Blockchain Assistant",
|
26 |
description="Geben Sie einen Text ein, und das Modell generiert eine Fortsetzung."
|
27 |
)
|
28 |
|
29 |
+
# Starte die Gradio-App
|
30 |
if __name__ == "__main__":
|
31 |
interface.launch()
|