Skip to content

Commit

Permalink
Merge pull request #5 from Devparihar5/test_v1
Browse files Browse the repository at this point in the history
Test v1
  • Loading branch information
Devparihar5 authored Mar 15, 2024
2 parents aa7eefe + db499db commit 367b28b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
32 changes: 14 additions & 18 deletions Upload_Your_Video.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@
from utils.document_processor import DocumentProcessor
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
import ctypes

import os



# function to create pdf of transcription
def generate_pdf_report(transcription):
output_pdf_path = "tempfiles/transcription.pdf"
c = canvas.Canvas(output_pdf_path, pagesize=letter)
max_width = letter[0] - 100 # Max width of the PDF minus some margin
y = 750 # Starting y position
max_width = letter[0] - 100
y = 750
for line in transcription.split('\n'):
words = line.split()
x = 50 # Starting x position
x = 50
for word in words:
if c.stringWidth(word, "Helvetica", 12) + x > max_width:
y -= 12 # Move to the next line
x = 50 # Reset x position
y -= 12
x = 50
c.drawString(x, y, word)
x += c.stringWidth(word + " ", "Helvetica", 12) # Move x to the end of the word
y -= 12 # Move to the next line
y -= 12
c.save()


# setting HUGGINGFACEHUB_API_TOKEN as env variable
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HUGGINGFACEHUB_API_TOKEN"]

with open("style.css", "r") as file:
Expand Down Expand Up @@ -85,25 +82,20 @@ def generate_pdf_report(transcription):
video = yt.streams.get_highest_resolution()
output_video_path = "videos"
if os.path.exists(output_video_path):
# Get a list of all items in the directory
items = os.listdir(output_video_path)

# Loop through the list of items and delete each file
for item in items:
item_path = os.path.join(output_video_path, item)
if os.path.isfile(item_path):
os.remove(item_path)

video.download(output_video_path)
if os.path.exists(output_video_path):
# Get a list of all items in the directory
items = os.listdir(output_video_path)

# Find the first video file and rename it
for item in items:
item_path = os.path.join(output_video_path, item)
if os.path.isfile(item_path) and item.lower().endswith(".mp4"):
# Rename the first video file found
os.rename(item_path, os.path.join(output_video_path, "sample_video.mp4"))
output_video_path = output_video_path + "\sample_video.mp4"
st.video(output_video_path)
Expand All @@ -114,16 +106,20 @@ def generate_pdf_report(transcription):
converter = VideoToAudioConverter(output_video_path)
converter.convert_to_audio(output_audio_path)
progress_bar.progress(30)
progress_text = st.empty()


progress_text.write("Transcribing audio...")
transcriber = AudioTranscriber()
transcription = transcriber.transcribe(output_audio_path)
generate_pdf_report(transcription)
progress_bar.progress(70)
progress_text = st.empty()

progress_text.write("Processing document...")
document_processor = DocumentProcessor()
updated_vector = document_processor.process_document()
progress_text.write("100% Complete!")

progress_bar.progress(100)
except Exception as e:
st.error(f"Error: {str(e)}")
st.error(f"Error: {str(e)}")
Binary file added images/chat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/video-upload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion utils/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch

class AudioTranscriber:
def __init__(self, model_id="openai/whisper-tiny.en", cache_dir=r'./'):
def __init__(self, model_id="openai/whisper-tiny.en", cache_dir=r'./cache/'):
self.processor = WhisperProcessor.from_pretrained(model_id, cache_dir=cache_dir)
self.model = WhisperForConditionalGeneration.from_pretrained(model_id, cache_dir=cache_dir)
self.device = "cuda" if torch.cuda.is_available() else "cpu"
Expand Down

0 comments on commit 367b28b

Please sign in to comment.