BoldStudio's picture
Update app.py
abf4233
import gradio as gr
from gradio_client import Client
import ast
def call_api(transcript):
client = Client("http://47.103.63.15:50085/")
prompt = """
INSTRUCTIONS:
Convert this Transcript into Segment Cards.
IMPORTANT:
- Maintain Language Consistency: Ensure that the language used in segment cards matches the transcription for clarity.
- Verify Duration Accuracy: Double-check that the stated duration of each segment card accurately reflects the content's length.
- Avoid Special Characters and Emojis: Refrain from using special characters or emojis in segment card descriptions for a clean and professional appearance.
- There should be exactly the same number of segment cards as the transcript has segments
- Match the Number of Segment Cards: Create a segment card for each segment in the transcription to align with the video content.
- Focus Solely on Segment Cards: Output only the segment cards without any additional text or commentary.
- Implement <card> Tags: Properly format each segment card by including <card> tags before and after the card content.
- Precision and Completeness: Craft each segment card with precision and ensure it contains complete and relevant information.
- Adhere to Output Format: Format your answers according to the specified Output Format.
- Consider YouTube Short Video Rating: Evaluate the content's quality in terms of suitability for YouTube Short videos when providing a rating.
- Make Sure the Title is no more than 50 characters
- Make Sure the Description is no more than 100 characters
- emphasize the importance of using the same language as the transcript in segment cards to ensure coherence and accuracy.
- use the same language for your answer as the transcript
- Only Output 1 Segment Card for each Segment in the Transcription
CONTENT OF CARD:
{
Title: (max. 50 Characters)
Description: (summary of content max. 140 Characters)
Rating: 1-5
Duration: [00:00.000 - 00:00.000]
}
TRANSCRIPT:
"""
transcript = str(transcript)
result = client.predict(
prompt + transcript,
0.9,
2048,
api_name="/predict"
)
return result
def transcription_to_segments(transcript):
transcript = ast.literal_eval(transcript)
segment_cards_array = []
for segment in transcript:
result = call_api(segment)
segment_cards_array.append(result)
return segment_cards_array
# Define the Gradio interface for transcription and segmentation
interface = gr.Interface(
fn=transcription_to_segments,
inputs="text",
outputs="textbox"
)
# Launch the Gradio interface
interface.launch()