Spaces:
Running
Running
import asyncio | |
import streamlit as st | |
from pydantic_ai import Agent | |
from pydantic_ai.models.groq import GroqModel | |
import nest_asyncio | |
import pdfplumber | |
import os | |
api_key = os.getenv("API_KEY") | |
data = [] | |
#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 | |
model = GroqModel('llama-3.1-70b-versatile', api_key = api_key) | |
async def ppt_content(data): | |
agent = Agent(model,system_prompt=( | |
"You are an expert in making power-point perssentation", | |
"Convert the content of the attached PDF into PowerPoint slides", | |
"Title Slide: Include the document's title, subtitle, author, and date.", | |
"Methodology Slide: Summarize the methodology in bullet points", | |
"Results Slide: Present key findings using tables or charts.", | |
"Discussion Slide: Summarize the implications and limitations.", | |
"Conclusion Slide: State the overall conclusion.", | |
"Reference Slide: Include all citations used." | |
)) | |
result_1 = agent.run_sync(user_prompt=data) | |
print(result_1.data) | |
def ai_ppt(data): | |
asyncio.run(ppt_content(data=data)) | |
def extract_data(feed): | |
with pdfplumber.open(feed) as pdf: | |
pages = pdf.pages | |
for p in pages: | |
data.append(p.extract_text()) | |
return None | |
uploaded_file = st.file_uploader('Choose your .pdf file', type="pdf") | |
if uploaded_file is not None: | |
df = extract_data(uploaded_file) | |
if data is not None: | |
st.caption(data) | |
ai_ppt(data=data) | |
# if __name__ == '__main__': | |
# import asyncio | |
# nest_asyncio.apply() | |
# asyncio.run(ppt_content()) | |