Spaces:
Sleeping
Sleeping
File size: 2,265 Bytes
7c264ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
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 <card> 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'<card>.*?</card>'
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()
|