Spaces:
Sleeping
Sleeping
Use docx as context for questions
Browse files
app.py
CHANGED
|
@@ -13,20 +13,25 @@ def read_docx(file_path):
|
|
| 13 |
for paragraph in doc.paragraphs:
|
| 14 |
text.append(paragraph.text)
|
| 15 |
return "\n".join(text)
|
|
|
|
| 16 |
|
|
|
|
| 17 |
user_input = st.text_input('Ask me a question')
|
| 18 |
-
messages = [{"role": "user","content": user_input}]
|
| 19 |
-
|
| 20 |
-
completion = client.chat.completions.create(
|
| 21 |
-
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 22 |
-
messages=messages,
|
| 23 |
-
max_tokens=500
|
| 24 |
-
)
|
| 25 |
|
| 26 |
if st.button("Submit"):
|
| 27 |
if user_input:
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
st.write(f"Adrega AI: {answer}")
|
| 31 |
else:
|
| 32 |
st.write("Please enter a question.")
|
|
|
|
| 13 |
for paragraph in doc.paragraphs:
|
| 14 |
text.append(paragraph.text)
|
| 15 |
return "\n".join(text)
|
| 16 |
+
context = read_docx(file_path)
|
| 17 |
|
| 18 |
+
st.title("Adrega AI Help")
|
| 19 |
user_input = st.text_input('Ask me a question')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
if st.button("Submit"):
|
| 22 |
if user_input:
|
| 23 |
+
messages = [
|
| 24 |
+
{"role": "system", "content": f"Context: {context}"
|
| 25 |
+
{"role": "user","content": user_input}
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
completion = client.chat.completions.create(
|
| 29 |
+
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 30 |
+
messages=messages,
|
| 31 |
+
max_tokens=500
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
answer = completion.choices[0].message['content']
|
| 35 |
st.write(f"Adrega AI: {answer}")
|
| 36 |
else:
|
| 37 |
st.write("Please enter a question.")
|