JuanPablo4to commited on
Commit
c8ab9aa
verified
1 Parent(s): f30ca05

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ model_id = "meta-llama/Meta-Llama-3-8B"
5
+
6
+ # Initialize the model pipeline
7
+ pipe = pipeline("text-generation", model=model_id)
8
+
9
+ # Display the logo and title
10
+ st.image("logo.jpg", width=300)
11
+ st.title("Coach Virtual PRODI")
12
+
13
+ # Initialize a session state variable for history if it doesn't exist
14
+ if 'history' not in st.session_state:
15
+ st.session_state['history'] = []
16
+
17
+ # Function to update the conversation history
18
+ def update_history(user_input, ai_response):
19
+ st.session_state['history'].append(("User", user_input))
20
+ st.session_state['history'].append(("AI", ai_response))
21
+
22
+ # Display the conversation history
23
+ for speaker, text in st.session_state['history']:
24
+ if speaker == "User":
25
+ st.text_input("Usuario", value=text, disabled=True)
26
+ else:
27
+ st.text_area("PRODI", value=text, height=75, disabled=True)
28
+
29
+ # Chat input for user prompt
30
+ user_input = st.text_input("驴C贸mo te puedo ayudar hoy?")
31
+ if user_input:
32
+ with st.spinner("Generando respuesta..."):
33
+ # Get the AI's response
34
+ ai_response = pipe(user_input, max_length=100, num_return_sequences=1)[0]['generated_text']
35
+
36
+ # Update the conversation history
37
+ update_history(user_input, ai_response)
38
+
39
+ # Display the AI's response
40
+ st.write(ai_response)