import gradio as gr from gradio_client import Client import re def call_api(transcript): client = Client( "https://huggingface-projects-llama-2-13b-chat.hf.space/--replicas/dknmg/") prompt = """ INSTRUCTIONS: Convert this Transcript into Segment Cards. IMPORTANT: - use the same language from the transcription to write the segment cards. - make sure that the duration is correct. - dont use special characters or emojis in the description - write as many segment cards as the transcription has - only output the segment cards - dont answer with additional text - Add a tag before and after every segment card - be precise and make sure every segment card is complete - Your Answer should be like the Output Format CONTENT OF CARD: { Title: (max. 50 Characters) Description: (summary of content max. 140 Characters) Rating: 1-5 (How Relevant is this content in relation to the transript and how good is this topic for a youtube short video) Duration: [00:00.000 - 00:00.000] } TRANSCRIPT: """ transcript = str(transcript) result = client.predict( transcript, prompt, 1024, 0.6, 0.9, 50, 1.2, api_name="/chat" ) return result def transcription_to_segments(segments): segment_cards_array = [] card_pattern = r'.*?' for segment in segments: result = call_api(segment) card_matches = re.findall(card_pattern, result, re.DOTALL) for card_match in card_matches: card_object = { "Title": re.search(r'Title: (.*?)\n', card_match).group(1), "Description": re.search(r'Description: (.*?)\n', card_match).group(1), "Rating": re.search(r'Rating: (.*?)\n', card_match).group(1), "Duration": re.search(r'Duration: (.*?)\n', card_match).group(1) } segment_cards_array.append(card_object) return segment_cards_array # Define the Gradio interface for transcription and segmentation interface = gr.Interface( fn=transcription_to_segments, inputs="text", outputs="json" ) # Launch the Gradio interface interface.launch()