Spaces:
Sleeping
Sleeping
Update app.py
Browse files13 unmodified lines141516171819208 unmodified lines293031323334353637383940414243444546474849504 unmodified lines55565758596061626313 unmodified linesgroq_client = Groq(api_key=groq_api_key)# Load Whisper modelmodel = whisper.load_model("base")8 unmodified linesdoc = Document(file.name)text = ''.join([para.text for para in doc.paragraphs])else:return "Unsupported file format. Please upload a PDF or DOCX file."# Generate summarychat_completion = client.chat.completions.create(messages=[{"role": "user", "content": f"Please summarize the following text: {text}"}],model="llama3-8b-8192",)summary = chat_completion.choices[0].message.content# Convert summary text to speech using gTTStts = gTTS(text=summary, lang='en')audio_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')tts.save(audio_file.name)return summary, audio_file.name4 unmodified linesoutputs=[gr.Textbox(label="Summary"), gr.Audio(label="Audio Summary")],title="Document Summarizer",description="Upload a Word or PDF document and get a summary with audio playback.",theme=gr.themes.Monochrome())# Launch the interface with sharing enablediface.launch(share=True, debug=True)13 unmodified lines1415161718198 unmodified lines282930313233343536373839404142434445464748495051525354554 unmodified lines606162636465666713 unmodified linesgroq_client = Groq(api_key=groq_api_key)# Load Whisper modelmodel = whisper.load_model("base")8 unmodified linesdoc = Document(file.name)text = ''.join([para.text for para in doc.paragraphs])else:return "Unsupported file format. Please upload a PDF or DOCX file.", None# Generate summarytry:chat_completion = groq_client.chat.completions.create(messages=[{"role": "user", "content": f"Please summarize the following text: {text}"}],model="llama3-8b-8192",)summary = chat_completion.choices[0].message.contentexcept Exception as e:return f"Error generating summary: {e}", None# Convert summary text to speech using gTTStry:tts = gTTS(text=summary, lang='en')audio_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')tts.save(audio_file.name)audio_file.close()except Exception as e:return f"Error generating audio: {e}", Nonereturn summary, audio_file.name4 unmodified linesoutputs=[gr.Textbox(label="Summary"), gr.Audio(label="Audio Summary")],title="Document Summarizer",description="Upload a Word or PDF document and get a summary with audio playback.",theme=gr.themes.Monochrome())# Launch the interface with sharing enablediface.launch(share=False, debug=True) # Use `share=True` if deploying elsewhere
app.py+20-16