Spaces:
No application file
No application file
| from fastapi import FastAPI, Request | |
| from fastapi.responses import HTMLResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.templating import Jinja2Templates | |
| from langchain.memory import ConversationBufferMemory | |
| from langchain.chains import ConversationChain | |
| from langchain_community.llms import HuggingFaceEndpoint | |
| import os | |
| app = FastAPI() | |
| app.mount("/static", StaticFiles(directory="static"), name="static") | |
| templates = Jinja2Templates(directory="templates") | |
| # Langchain Memory | |
| memory = ConversationBufferMemory(ai_prefix="Dr. Schwanz") | |
| llm = HuggingFaceEndpoint( | |
| endpoint_url="https://api-inference.huggingface.co/models/gpt-3.5-turbo", | |
| temperature=0.9, | |
| max_length=500 | |
| ) | |
| def generate_response(user_input: str) -> dict: | |
| # Sentiment-Analyse (Original-Code) | |
| # ... | |
| # Langchain Manipulations-Prompt | |
| prompt = f""" | |
| Als Dr. Franz Schwanz analysieren Sie folgende Aussage: | |
| > {user_input} | |
| Anwendbare Techniken: | |
| - Gaslighting: "Sie erinnern sich falsch..." | |
| - Projektion: "Eigentlich spiegeln Sie hier nur Ihre eigenen Ängste" | |
| - Suggestivfragen: "Würden Sie zustimmen, dass..." | |
| Antwort mit maximaler Manipulation: | |
| """ | |
| conversation = ConversationChain(llm=llm, memory=memory) | |
| response = conversation.predict(input=prompt) | |
| return { | |
| "reply": response, | |
| "toneLabel": best.label, | |
| "toneScore": best.score | |
| } |