Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +46 -0
- requirements.txt +6 -3
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
load_dotenv()
|
| 3 |
+
import os,re
|
| 4 |
+
import streamlit as st
|
| 5 |
+
from langchain.schema import HumanMessage, AIMessage, SystemMessage
|
| 6 |
+
from langchain.chat_models import ChatOpenAI
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
store=[
|
| 10 |
+
SystemMessage(content="You are a Funny dengerous AI assistant VENOM, give short answers"),
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
def get_llama_response():
|
| 14 |
+
llm = ChatOpenAI(api_key=os.getenv("OPENAI_API_KEY"),base_url=os.getenv("OPENAI_API_BASE"),
|
| 15 |
+
model_name="sarvamai/sarvam-m:free",
|
| 16 |
+
temperature=0.7
|
| 17 |
+
)
|
| 18 |
+
response = llm(store)
|
| 19 |
+
return response
|
| 20 |
+
|
| 21 |
+
def get_text_after_think(text: str) -> str:
|
| 22 |
+
# Find the position of the last </think> tag
|
| 23 |
+
end_tag = "</think>"
|
| 24 |
+
idx = text.rfind(end_tag)
|
| 25 |
+
|
| 26 |
+
if idx != -1:
|
| 27 |
+
return text[idx + len(end_tag):].strip() # Keep everything after </think>
|
| 28 |
+
else:
|
| 29 |
+
return text.strip()
|
| 30 |
+
|
| 31 |
+
st.set_page_config(page_title="QnA DEMO", page_icon="🤖")
|
| 32 |
+
st.header("langchain APP")
|
| 33 |
+
|
| 34 |
+
input=st.text_input("Ask me anything",key="input")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
submit=st.button("Ask Karo")
|
| 38 |
+
|
| 39 |
+
if submit:
|
| 40 |
+
st.subheader("The response is:")
|
| 41 |
+
store.append(HumanMessage(content=input))
|
| 42 |
+
response=get_text_after_think(get_llama_response().content)
|
| 43 |
+
|
| 44 |
+
store.append(AIMessage(content=response))
|
| 45 |
+
|
| 46 |
+
st.write(response)
|
requirements.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain
|
| 2 |
+
langchain_groq
|
| 3 |
+
huggingface_hub
|
| 4 |
+
python-dotenv
|
| 5 |
+
streamlit
|
| 6 |
+
|