Spaces:
Runtime error
Runtime error
Uploaded app.py and requirements.txt
Browse files- app.py +42 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.llms import OpenAI
|
2 |
+
import os
|
3 |
+
import streamlit as st
|
4 |
+
from langchain.chat_models import ChatOpenAI
|
5 |
+
from langchain.prompts.chat import ChatPromptTemplate
|
6 |
+
from langchain.schema import BaseOutputParser
|
7 |
+
|
8 |
+
|
9 |
+
chat_llm = ChatOpenAI(temperature=0.5, model='gpt-3.5-turbo')
|
10 |
+
|
11 |
+
class CommaseperatedOutput(BaseOutputParser):
|
12 |
+
def parse(self, text:str):
|
13 |
+
return text
|
14 |
+
|
15 |
+
|
16 |
+
# function to call openai api and get response
|
17 |
+
def get_response(question):
|
18 |
+
template = "You are a naughty assistant who is great at flirting. You have to make a cheesy pickup line by using words given by user."
|
19 |
+
human_template = "{text}"
|
20 |
+
chatprompt = ChatPromptTemplate.from_messages([
|
21 |
+
('system', template),
|
22 |
+
('human', human_template)])
|
23 |
+
|
24 |
+
chain = chatprompt|chat_llm|CommaseperatedOutput()
|
25 |
+
|
26 |
+
response = chain.invoke({"text":question})
|
27 |
+
|
28 |
+
return response
|
29 |
+
# create streamlit app
|
30 |
+
|
31 |
+
st.set_page_config(page_title="Langchain Application")
|
32 |
+
|
33 |
+
st.header("Your Flirting Guardian")
|
34 |
+
|
35 |
+
input = st.text_input("You give me words and I will give you a pickup line: ", key="input")
|
36 |
+
response = get_response(input)
|
37 |
+
|
38 |
+
|
39 |
+
submit = st.button("Get a pickup line")
|
40 |
+
if submit:
|
41 |
+
st.subheader("Here is your pickup line")
|
42 |
+
st.write(response)
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
openai
|
3 |
+
huggingface_hub
|
4 |
+
python-dotenv
|
5 |
+
streamlit
|