Spaces:
Runtime error
Runtime error
Update app.py
#5
by
aebcnp
- opened
app.py
CHANGED
@@ -1,7 +1,17 @@
|
|
1 |
import os
|
2 |
from groq import Groq
|
3 |
import gradio as gr
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
client = Groq(api_key = os.environ.get("GROQ_API_KEY"), )
|
6 |
|
7 |
system_prompt = {
|
@@ -22,7 +32,11 @@ async def chat_groq(message, history):
|
|
22 |
|
23 |
messages.append({"role": "user", "content": message["text"]})
|
24 |
|
25 |
-
file_path = message
|
|
|
|
|
|
|
|
|
26 |
|
27 |
response_content = ''
|
28 |
|
|
|
1 |
import os
|
2 |
from groq import Groq
|
3 |
import gradio as gr
|
4 |
+
import fitz
|
5 |
+
|
6 |
+
def extract_text_from_pdf(file_path):
|
7 |
+
text = ""
|
8 |
+
document = fitz.open(file_path)
|
9 |
+
for page_num in range(len(document)):
|
10 |
+
page = document.load_page(page_num)
|
11 |
+
text += page.get_text()
|
12 |
+
document.close()
|
13 |
+
return text
|
14 |
+
|
15 |
client = Groq(api_key = os.environ.get("GROQ_API_KEY"), )
|
16 |
|
17 |
system_prompt = {
|
|
|
32 |
|
33 |
messages.append({"role": "user", "content": message["text"]})
|
34 |
|
35 |
+
file_path = message.get("files")
|
36 |
+
if file_path:
|
37 |
+
pdf_text = extract_text_from_pdf(file_path)
|
38 |
+
messages.append({"role": "user", "content": pdf_text})
|
39 |
+
|
40 |
|
41 |
response_content = ''
|
42 |
|