Spaces:
Build error
Build error
Commit ·
4edf1b3
1
Parent(s): 1c0e7e6
Update app.py
Browse files123456789101112131415161718192021import gradio as grfrom gpt_index import GPTSimpleVectorIndexfrom gpt_index.langchain_helpers.chain_wrapper import OpenAIimport osos.environ["OPENAI_API_KEY"] = "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"index = GPTSimpleVectorIndex.load_from_disk('./index (4).json')def my_model_function(input_text):response = index.query(input_text, response_mode="compact")return responseiface = gr.Interface(fn=my_model_function,inputs=gr.inputs.Textbox(label="Enter your question here"),outputs="text",title="GPT Index Demo",description="Type a question and see the matching responses from the index!")iface.launch()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import jsonimport reimport textwrapimport openaiimport gradio as grdef gpt3_completion(prompt, engine='text-davinci-002', temp=0.6, top_p=1.0, tokens=1000, freq_pen=0.25, pres_pen=0.0, stop=['<<END>>']):print("here");max_retry = 5retry = 0response = openai.Completion.create(engine=engine,prompt=prompt,temperature=0.7,max_tokens=963,top_p=1,frequency_penalty=0,presence_penalty=0)text = response['choices'][0]['text'].strip()text = re.sub('\s+', ' ', text)return textdef summarize_podcast(podcast):# Open the transcript filevtt = podcasttranscript = vtt.read().decode()res = len(transcript.split())transcript = transcript.replace("WEBVTT", "")transcript = "\n".join(filter(None, transcript.splitlines()))transcript = re.sub(r"\d\d:\d\d:\d\d\.\d\d\d \d\d:\d\d:\d\d\.\d\d\d", "", transcript)text = transcriptlines = text.split('\n')names = []unique_list=[]for line in lines:if ':' in line:name = line.split(':')[0]names.append(name)for x in range(0,len(names)):if names[x] not in unique_list:unique_list.append(names[x])sp=""al=["A","B","C","D","E","F","G","H","I","K","L","M","N","O","P","Q","R","S","T","V","X","Y","Z"]for x in range(0,len(unique_list)):transcript = transcript.replace(unique_list[x], al[x])sp=sp+"Speaker "+str(x+1)+" "+unique_list[x]+"\n"transcript=sp+""+transcriptopenai.api_key = "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"chunks = textwrap.wrap(transcript, 8000)result = list()count = 0tempstr=""for chunk in chunks:count = count + 1prompt = sp+"""\nSummarize the portion of the podcast. The summary should be around 200 words. use the Name instead of A, B, C...Podcast:"""+str(chunk)+"""'\n\n"""summary = gpt3_completion(prompt)summary="chunk : "+str(count)+summaryresult.append(summary)tempstr=tempstr+"\n"+summaryreturn str(tempstr)input_file = gr.inputs.File(label="Upload your podcast in VTT format.")output_text = gr.outputs.Textbox(label="Podcast Summary")sample_url = "https://www.example.com/sample.vtt"iface = gr.Interface(fn=summarize_podcast, inputs=input_file, outputs=output_text, title="Podcast Summarizer",description="This tool summarizes a podcast in VTT format, providing a summary of each chunk of text.")iface.launch()
app.py+76-20