ariankhalfani commited on
Commit
0c103d5
1 Parent(s): 7e6cd24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -15,7 +15,10 @@ HEADERS = {"Authorization": f"Bearer {HF_API_TOKEN}"}
15
 
16
  def query_model(api_url, payload):
17
  response = requests.post(api_url, headers=HEADERS, json=payload)
18
- return response.json()
 
 
 
19
 
20
  def extract_pdf_text(uploaded_file):
21
  pdf_text = ""
@@ -29,6 +32,10 @@ st.set_page_config(page_title="Gemma 27B-it Chatbot Interface", layout="wide")
29
  st.title("Gemma 27B-it Chatbot Interface")
30
  st.write("Gemma 27B-it Chatbot Interface")
31
 
 
 
 
 
32
  # File uploader for PDF
33
  uploaded_file = st.file_uploader("Upload a PDF", type="pdf")
34
 
@@ -48,6 +55,7 @@ if st.button("Send") and question:
48
  response = query_model(GEMMA_27B_API_URL, {"inputs": question})
49
  answer = response.get("generated_text", "No response")
50
  st.write(f"**Gemma 27B-it:** {answer}")
 
51
  except ValueError as e:
52
  st.error(str(e))
53
 
@@ -86,10 +94,4 @@ if st.session_state.conversation:
86
  for user_message, bot_message in st.session_state.conversation:
87
  st.write(f'<div class="user-message">You: {user_message}</div>', unsafe_allow_html=True)
88
  st.write(f'<div class="bot-message">Gemma 27B-it: {bot_message}</div>', unsafe_allow_html=True)
89
- st.write('</div>', unsafe_allow_html=True)
90
-
91
- # Add the current interaction to the conversation
92
- if question:
93
- st.session_state.conversation.append((question, answer))
94
- else:
95
- st.session_state.conversation = []
 
15
 
16
  def query_model(api_url, payload):
17
  response = requests.post(api_url, headers=HEADERS, json=payload)
18
+ if response.status_code == 200:
19
+ return response.json()
20
+ else:
21
+ raise ValueError(f"Request failed with status code {response.status_code}: {response.text}")
22
 
23
  def extract_pdf_text(uploaded_file):
24
  pdf_text = ""
 
32
  st.title("Gemma 27B-it Chatbot Interface")
33
  st.write("Gemma 27B-it Chatbot Interface")
34
 
35
+ # Initialize session state for conversation and uploaded file
36
+ if "conversation" not in st.session_state:
37
+ st.session_state.conversation = []
38
+
39
  # File uploader for PDF
40
  uploaded_file = st.file_uploader("Upload a PDF", type="pdf")
41
 
 
55
  response = query_model(GEMMA_27B_API_URL, {"inputs": question})
56
  answer = response.get("generated_text", "No response")
57
  st.write(f"**Gemma 27B-it:** {answer}")
58
+ st.session_state.conversation.append((question, answer))
59
  except ValueError as e:
60
  st.error(str(e))
61
 
 
94
  for user_message, bot_message in st.session_state.conversation:
95
  st.write(f'<div class="user-message">You: {user_message}</div>', unsafe_allow_html=True)
96
  st.write(f'<div class="bot-message">Gemma 27B-it: {bot_message}</div>', unsafe_allow_html=True)
97
+ st.write('</div>', unsafe_allow_html=True)