How can I use Series with custom models from different sources

So Iโ€™m trying to create a project using transformers, datasets and gradio that is capable of scraping arabic news sites, translate articles, summarize them and then finally factcheck them.

Iโ€™ve already created all the modules necessary but now Iโ€™m kinda stuck at how I could chain all these together so I could make a simple GUI that ties it all together. My translator and summarizer modules are fine tuned models that I have uploaded to the huggingface hub but as for the fake news detector I created a tensorflow model for this purpose, saved the model and then created a predict function that would return the final result.

My code so far is:

scraper_obj = NewsScraper()

scraper = gr.Interface(fn=scraper_obj.scrape, inputs='text', outputs='text')

translator = gr.Interface.load(name='huggingface/vftnr/ArabicEnglishTranslation', api_key='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')

summarizer = gr.Interface.load(name='huggingface/vftnr/EnglishSummarization', api_key='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')

//factchecker = gr.Interface(fn=predict_news)

demo = gr.Series(scraper, translator, summarizer, factchecker)

demo.launch()

Iโ€™m kinda stuck at the fact checker line and how should I do it exactly.

hi @vftnr ,

The idea of Series is to chain your input โ†’ outputs โ†’ input โ†’ output to your different predictions functions and you will see the interface for first input and the final output component.

Letโ€™s say your Scraper input is URL (text) โ†’ content (text) โ†’ translator content (text) โ†’ translation (text) โ†’ summarizer content (text) โ†’ summary (text) โ†’ fact checker content (text) โ†’ ?? maybe a label with probabilities, or maybe a dataframe with results?

Iโ€™m not sure of the internals of your interfaces, but just make sure theyโ€™re expecting the right inputs and outputs.

ps:
You can invalidate and refresh your access tokens, because theyโ€™re private, this forum is public.


# scraper_obj = NewsScraper()

scraper = gr.Interface(fn=lambda x: x, inputs='text', outputs='text')

translator = gr.Interface.load(name='huggingface/vftnr/ArabicEnglishTranslation', api_key='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')

summarizer = gr.Interface.load(name='huggingface/vftnr/EnglishSummarization', api_key='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')

factchecker = gr.Interface(fn=lambda x: x, inputs='text', outputs='text')

demo = gr.Series(scraper, translator, summarizer, factchecker)

demo.launch()
2 Likes