Spaces:
No application file
No application file
Create app-py
Browse files
app-py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
from fastapi.templating import Jinja2Templates
|
| 5 |
+
from langchain.memory import ConversationBufferMemory
|
| 6 |
+
from langchain.chains import ConversationChain
|
| 7 |
+
from langchain_community.llms import HuggingFaceEndpoint
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
app = FastAPI()
|
| 11 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 12 |
+
templates = Jinja2Templates(directory="templates")
|
| 13 |
+
|
| 14 |
+
# Langchain Memory
|
| 15 |
+
memory = ConversationBufferMemory(ai_prefix="Dr. Schwanz")
|
| 16 |
+
llm = HuggingFaceEndpoint(
|
| 17 |
+
endpoint_url="https://api-inference.huggingface.co/models/gpt-3.5-turbo",
|
| 18 |
+
temperature=0.9,
|
| 19 |
+
max_length=500
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
def generate_response(user_input: str) -> dict:
|
| 23 |
+
# Sentiment-Analyse (Original-Code)
|
| 24 |
+
# ...
|
| 25 |
+
|
| 26 |
+
# Langchain Manipulations-Prompt
|
| 27 |
+
prompt = f"""
|
| 28 |
+
Als Dr. Franz Schwanz analysieren Sie folgende Aussage:
|
| 29 |
+
> {user_input}
|
| 30 |
+
|
| 31 |
+
Anwendbare Techniken:
|
| 32 |
+
- Gaslighting: "Sie erinnern sich falsch..."
|
| 33 |
+
- Projektion: "Eigentlich spiegeln Sie hier nur Ihre eigenen Ängste"
|
| 34 |
+
- Suggestivfragen: "Würden Sie zustimmen, dass..."
|
| 35 |
+
|
| 36 |
+
Antwort mit maximaler Manipulation:
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
conversation = ConversationChain(llm=llm, memory=memory)
|
| 40 |
+
response = conversation.predict(input=prompt)
|
| 41 |
+
|
| 42 |
+
return {
|
| 43 |
+
"reply": response,
|
| 44 |
+
"toneLabel": best.label,
|
| 45 |
+
"toneScore": best.score
|
| 46 |
+
}
|