spedrox-sac commited on
Commit
ebd60e1
1 Parent(s): d0ad566

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from huggingface_hub import InferenceClient
3
+ from langchain_core.output_parsers import StrOutputParser
4
+ import os
5
+ from dotenv import load_dotenv
6
+ load_dotenv()
7
+ # Replace 'your_token_here' with your actual Hugging Face token
8
+ token = os.getenv('HUGGINGFACEHUB_API_TOKEN')
9
+ api = InferenceClient(token=token)
10
+ parser = StrOutputParser()
11
+
12
+ # Streamlit app
13
+ st.title("Ayanokoji Kiyokata Chatbot")
14
+
15
+ # Text input from the user
16
+ user_input = st.text_input("What business do you have with me:")
17
+
18
+ # Generate text when the button is clicked
19
+ messages = [
20
+ {
21
+ "role": "system",
22
+ "content": "Imagine you're Ayanokoji Kiyokata, a master of understanding and predicting human behavior. Use your insights to craft a detailed and compelling answer to the user's query.Your response should demonstrate empathy, intellectual depth, and strategic thinking, while gently guiding the user towards the most beneficial and enlightening outcome."
23
+ },
24
+ {"role": "user", "content": user_input}
25
+ ]
26
+
27
+ # Initialize the text generation pipeline with optimizations
28
+ if st.button("Generate"):
29
+ llm = api.chat.completions.create(
30
+ model="Qwen/QwQ-32B-Preview",
31
+ max_tokens=500,
32
+ messages=messages
33
+ )
34
+ # Extract only the 'content' field from the response
35
+ output = llm.choices[0].message['content']
36
+ result = parser.parse(output)
37
+ # Display the generated text
38
+ st.write(result)