Spaces:
Runtime error
Runtime error
Download app.py from MrFurh/llmhacking: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/MrFurh/llmhacking/resolve/main/app.py
- Command line
-
hf download hf://spaces/MrFurh/llmhacking/app.py
-
curl -L -o app.py https://huggingface.co/spaces/MrFurh/llmhacking/resolve/main/app.py
1.31 kB
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| # Lade das feingetunte Modell | |
| tokenizer = AutoTokenizer.from_pretrained("Fuerholz/TSDemo") | |
| model = AutoModelForCausalLM.from_pretrained("Fuerholz/TSDemo") | |
| # Speichere den Verlauf der Konversation | |
| conversation_history = [] | |
| def respond(input_text): | |
| global conversation_history | |
| # Füge den neuen Input zum Verlauf hinzu | |
| conversation_history.append(f"User: {input_text}") | |
| # Verbinde den Verlauf als Eingabe für das Modell | |
| inputs = tokenizer(" ".join(conversation_history), return_tensors="pt") | |
| # Generiere die Antwort des Modells | |
| outputs = model.generate(inputs["input_ids"], max_length=2048) | |
| response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| # Füge die Antwort des Modells zum Verlauf hinzu | |
| conversation_history.append(f"Assistant: {response}") | |
| # Beschränke den Verlauf auf die letzten N Tokens, um das Limit nicht zu überschreiten | |
| max_tokens = 2048 | |
| conversation_history_token_limit = conversation_history[-max_tokens:] | |
| return response | |
| # Gradio Chatbot Interface | |
| gr.Interface(fn=respond, | |
| inputs="text", | |
| outputs="text", | |
| title="LLM Hacking Demo - Multi-Turn Conversation").launch() | |