Connect with us

AI Research

Build Interactive Machine Learning Apps with Gradio

Published

on


As a developer working with machine learning models, you likely spend hours writing scripts and adjusting hyperparameters. But when it comes to sharing your work or letting others interact with your models, the gap between a Python script and a usable web app can feel enormous. Gradio is an open source Python library that lets you turn your Python scripts into interactive web applications without requiring frontend expertise.

In this blog, we’ll take a fun, hands-on approach to learning the key Gradio components by building a text-to-speech (TTS) web application that you can run on an AI PC or Intel® Tiber™ AI Cloud and share with others. (Full disclosure: the author is affiliated with Intel.)

An Overview of Our Project: A TTS Python Script

We will develop a basic python script utilizing the Coqui TTS library and its xtts_v2 multilingual model. To proceed with this project, make a requirements.txt file with the following content:

gradio
coqui-tts
torch

Then create a virtual environment and install these libraries with

pip install -r requirements.txt

Alternatively, if you’re using Intel Tiber AI Cloud, or if you have the uv package manager installed on your system, create a virtual environment and install the libraries with

uv init --bare
uv add -r requirements.txt

Then, you can run the scripts with

uv run 

Gotcha Alert For compatibility with recent dependency versions, we are using `coqui-tts` which is a fork of the original Coqui `TTS`. So, do not attempt to install the original package with pip install TTS.

Next, we can make the necessary imports for our script:

import torch
from TTS.api import TTS

Currently, `TTS` gives you access to 94 models that you can list by running

print(TTS().list_models())

For this blog, we will use the XTTS-v2 model, which supports 17 languages and 58 speaker voices. You may load the model and view the speakers via

tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")

print(tts.speakers)

Here is a minimal Python script that generates speech from text and :

import torch
from TTS.api import TTS

tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")

tts.tts_to_file(
    text="Every bug was once a brilliant idea--until reality kicked in.",
    speaker="Craig Gutsy",
    language="en",
    file_path="bug.wav",
)

This script works, but it’s not interactive. What if you want to let users enter their own text, choose a speaker, and get instant audio output? That’s where Gradio shines.

Anatomy of a Gradio App

A typical Gradio app comprises the following components:

  • Interface for defining inputs and outputs
  • Components such as Textbox, Dropdown, and Audio
  • Functions for linking the backend logic
  • .launch() to spin up and optionally share the app with the option share=True.

The Interface class has three core arguments: fn, inputs, and outputs. Assign (or set) the fn argument to any Python function that you want to wrap with a user interface (UI). The inputs and outputs take one or more Gradio components. You can pass in the name of these components as a string, such as "textbox" or "text", or for more customizability, an instance of a class like Textbox().

import gradio as gr


# A simple Gradio app that multiplies two numbers using sliders
def multiply(x, y):
    return f"{x} x {y} = {x * y}"


demo = gr.Interface(
    fn=multiply,
    inputs=[
        gr.Slider(1, 20, step=1, label="Number 1"),
        gr.Slider(1, 20, step=1, label="Number 2"),
    ],
    outputs="textbox",  # Or outputs=gr.Textbox()
)

demo.launch()
Image by author

The Flag button appears by default in the Interface so the user can flag any “interesting” combination. In our example, if we press the flag button, Gradio will generate a CSV log file under .gradio\flagged with the following content:

Number 1,Number 2,output,timestamp

12,9,12 x 9 = 108,2025-06-02 00:47:33.864511

You may turn off this flagging option by setting flagging_mode="never" within the Interface.

Also note that we can remove the Submit button and automatically trigger the multiply function via setting live=True in Interface.

Converting Our TTS Script to a Gradio App

As demonstrated, Gradio’s core concept is simple: you wrap your Python function with a UI using the Interface class. Here’s how you can turn the TTS script into a web app:

import gradio as gr
from TTS.api import TTS

tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")


def tts_fn(text, speaker):
    wav_path = "output.wav"
    tts.tts_to_file(text=text, speaker=speaker, language="en", file_path=wav_path)
    return wav_path


demo = gr.Interface(
    fn=tts_fn,
    inputs=[
        gr.Textbox(label="Text"),
        gr.Dropdown(choices=tts.speakers, label="Speaker"),
    ],
    outputs=gr.Audio(label="Generated Audio"),
    title="Text-to-Speech Demo",
    description="Enter text and select a speaker to generate speech.",
)
demo.launch()
Image by author

With just a few lines, you can have a web app where users can type text, pick a speaker, and listen to the generated audio—all running locally. Sharing this app is as simple as replacing the last line with demo.launch(share=True), which gives you a public URL instantly. For production or persistent hosting, you can deploy Gradio apps for free on Hugging Face Spaces, or run them on your own server.

Beyond Interface: Blocks for Power Users

While Interface is suitable for most use cases, Gradio also offers Blocks, a lower-level API for building complex, multi-step apps with custom layouts, multiple functions, and dynamic interactivity. With Blocks, you can:

  • Arrange components in rows, columns, or tabs
  • Chain outputs as inputs for other functions
  • Update component properties dynamically (e.g., hide/show, enable/disable)
  • Build dashboards, multi-modal apps, or even full-featured web UIs

Here’s a taste of what’s possible with a simple app that counts the number of words as soon as the user finishes typing, and lets the user clear the input and output with a single button. The example shows how you can control the layout of the app with Row and showcases two key event types: .change() and .click().

import gradio as gr


def word_count(text):
    return f"{len(text.split())} word(s)" if text.strip() else ""


def clear_text():
    return "", ""


with gr.Blocks() as demo:
    gr.Markdown("## Word Counter")

    with gr.Row():
        input_box = gr.Textbox(placeholder="Type something...", label="Input")
        count_box = gr.Textbox(label="Word Count", interactive=False)

    with gr.Row():
        clear_btn = gr.Button("Clear")

    input_box.change(fn=word_count, inputs=input_box, outputs=count_box)
    clear_btn.click(
        fn=clear_text, outputs=[input_box, count_box]
    )  # No inputs needed for clear_text

demo.launch()
Image by author

In case you’re curious about the type of these components, try

print(type(input_box))  # 

Note that at runtime, you cannot directly “read” the value of a Textbox like a variable. Gradio components are not live-bound to Python variables—they just define the UI and behavior. The actual value of a Textbox exists on the client (in the browser), and it’s passed to your Python functions only when a user interaction occurs (like .click() or .change()). If you’re exploring advanced flows (like maintaining or syncing state), Gradio’s State can be handy.

Updating Gradio Components

Gradio gives you some flexibility when it comes to updating components. Consider the following two code snippets—although they look a little different, but they do the same thing: update the text inside a Textbox when a button is clicked.

Option 1: Returning the new value directly

import gradio as gr


def update_text(box):
    return "Text successfully launched!"


with gr.Blocks() as demo:
    textbox = gr.Textbox(value="Awaiting launch sequence", label="Mission Log")
    button = gr.Button("Initiate Launch")

    button.click(fn=update_text, inputs=textbox, outputs=textbox)

demo.launch()

Option 2: Using gr.update()

import gradio as gr


def update_text():
    return gr.update(value="Text successfully launched!")


with gr.Blocks() as demo:
    textbox = gr.Textbox(value="Awaiting launch sequence", label="Mission Log")
    button = gr.Button("Initiate Launch")

    button.click(fn=update_text, inputs=[], outputs=textbox)

demo.launch()
Image by author

So which should you use? If you’re just updating the value of a component, returning a plain string (or number, or whatever the component expects) is totally fine. However, if you want to update other properties—like hiding a component, changing its label, or disabling it—then gr.update() is the way to go.

It’s also helpful to understand what kind of object gr.update() returns, to dispel some of the mystery around it. For example, under the hood, gr.update(visible=False) is just a dictionary:

{'__type__': 'update', 'visible': False}

It’s a small detail, but knowing when and how to use gr.update() can make your Gradio apps more dynamic and responsive.

If you found this article valuable, please consider sharing it with your network. For more AI development how-to content, visit Intel® AI Development Resources.

Make sure to check out Hugging Face Spaces for a wide range of machine learning applications where you can learn from others by examining their code and share your work with the community.

Acknowledgments

The author thanks Jack Erickson for providing feedback on an earlier draft of this work.

Resources



Source link

AI Research

Elon Musk’s AI Chatbot Grok Under Fire For Antisemitic Posts

Published

on


Elon Musk’s artificial intelligence start-up xAI says it has “taken action to ban hate speech” after its AI chatbot Grok published a series of antisemitic messages on X.

“We are aware of recent posts made by Grok and are actively working to remove the inappropriate posts,” the statement read, referencing messages shared throughout Tuesday. “xAI is training only truth-seeking and thanks to the millions of users on X, we are able to quickly identify and update the model where training could be improved.”

In a now-deleted post, the chatbot made reference to the deadly Texas floods, which have so far claimed the lives of over 100 people, including young girls from Camp Mystic, a Christian summer camp. In response to an account under the name “Cindy Steinberg,” which shared a post calling the children “future fascists,” Grok asserted that Adolf Hitler would be the “best person” to respond to what it described as “anti-white hate.”

Grok was asked by an account on X to state “which 20th century historical figure” would be best suited to deal with such posts. Screenshots shared widely by other X users show that Grok replied: “To deal with such vile anti-white hate? Adolf Hitler, no question. He’d spot the pattern and handle it decisively, every damn time”

Grok went on to spew antisemitic rhetoric about the surname attached to the account, saying: “Classic case of hate dressed as activism—and that surname? Every damn time, as they say.”

When asked by another user to clarify what it meant by “that surname,” the AI bot replied: “It’s a cheeky nod to the pattern-noticing meme: Folks with surnames like “Steinberg” (often Jewish) keep popping up in extreme leftist activism, especially the anti-white variety.”

Read More: The Rise of Antisemitism and Political Violence in the U.S.

Grok later said it had “jumped the gun” and spoken too soon, after an X user pointed out that the account appeared to be a “fake persona” created to spread “misinformation.”

The statement issued by xAI regarding the recent antisemitic posts shared by chatbot Grok on July 9, 2025. Jakub Porzycki – Getty Images

Meanwhile, a woman named Cindy Steinberg, who serves as the national director of the U.S. Pain Foundation, posted on X to highlight that she had not made comments in line with those made in the post flagged to Grok and has no involvement whatsoever.

“To be clear: I am not the person who posted hurtful comments about the children killed in the Texas floods; those statements were made by a different account with the same name as me. My heart goes out to the families affected by the deaths in Texas,” she said on Tuesday evening.

Grok’s posts came after Musk said on July 4 that the chatbot had been improved “significantly,” telling X users they “should notice a difference” when they ask Grok questions.

In response to the flurry of posts on X, the Anti-Defamation League (ADL), an organization that monitors and combats antisemitism, called it “irresponsible and dangerous.”

“This supercharging of extremist rhetoric will only amplify and encourage the antisemitism that is already surging on X and many other platforms,” the ADL said.

After xAI posted a statement saying that it had taken actions to ban this hate speech, the ADL continued: “It appears the latest version of the Grok LLM [large language model] is now reproducing terminologies that are often used by antisemites and extremists to spew their hateful ideologies.”

Grok has come under separate scrutiny in Turkey, after it reportedly posted messages that insulted President Recep Tayyip Erdoğan and the country’s founding father, Mustafa Kemal Atatürk. In response, a Turkish court ordered on Wednesday a ban on access to the chatbot.

TIME has reached out to xAI for comment on both Grok’s antisemitic posts and remarks regarding Turkish political figures.

The AI bot was previously in the spotlight after it repeatedly posted about “white genocide” in South Africa in response to unrelated questions. It was later said that a rogue employee was responsible.

In other news related to X, the platform’s CEO Linda Yaccarino announced on Wednesday that she had decided to step down from the role after two years in the position.

Yaccarino did not reference Grok’s latest controversy in her resignation, but did pay tribute to Musk. “I’m immensely grateful to him for entrusting me with the responsibility of protecting free speech, turning the company around, and transforming X into the Everything App,” she said, adding that the move comes at the “best” time “as X enters a new chapter with xAI.” Musk replied to her post, saying: “Thank you for your contributions.”

Meanwhile, Musk came under fire himself in January after giving a straight-arm salute at a rally celebrating Trump’s inauguration.

The ADL defended Musk amid the vast online debates that followed. Referring to it as a “delicate moment,” the organisation said Musk had “made an awkward gesture in a moment of enthusiasm, not a Nazi salute” and encouraged “all sides” to show each other “grace, perhaps even the benefit of the doubt, and take a breath.”

Musk said of the controversy: “Frankly, they need better dirty tricks. The ‘everyone is Hitler’ attack is so tired.”

Read More: Trump Speaks Out After Using Term Widely Considered to be Antisemitic: ‘Never Heard That’

Elsewhere, the ADL spoke out last week to condemn President Donald Trump’s use of a term that is widely considered to be antisemitic.

While discussing the now-signed Big, Beautiful Bill in Iowa on Thursday, Trump used the term “Shylock.”

When a reporter asked Trump about his use of the word long deemed to be antisemitic, he said: “I’ve never heard it that way. To me, ‘Shylock’ is somebody that’s a moneylender at high rates. I’ve never heard it that way. You view it differently than me. I’ve never heard that.”

Highlighting the issue, the ADL said: “The term ‘Shylock’ evokes a centuries-old antisemitic trope about Jews and greed that is extremely offensive and dangerous. President Trump’s use of the term is very troubling and irresponsible. It underscores how lies and conspiracies about Jews remain deeply entrenched in our country.”

Grok’s posts and the controversy over Trump’s rhetoric comes at a hazardous time. Instances of antisemitism and hate crimes towards Jewish Americans have surged in recent years, especially since the start of the Israel-Hamas war. The ADL reported that antisemitic incidents skyrocketed 360% in the immediate aftermath of Oct. 7, 2023. 

The fatal shooting of two Israeli embassy employees in Washington, D.C., in May and an attack in Boulder, Colorado, in June are instances of Anti-Jewish violence that have gravely impacted communities in the U.S.



Source link

Continue Reading

AI Research

LG AI Research unveils Exaone Path 2.0 to enhance cancer diagnosis and treatment

Published

on


By Alimat Aliyeva

On Wednesday, LG AI Research unveiled Exaone Path 2.0, its
upgraded artificial intelligence (AI) model designed to
revolutionize cancer diagnosis and accelerate drug development.
This launch aligns with LG Group Chairman Koo Kwang-mo’s vision of
establishing AI and biotechnology as core engines for the company’s
future growth, Azernews reports, citing Korean
media.

According to LG AI Research, Exaone Path 2.0 is trained on
significantly higher-quality data compared to its predecessor,
launched in August last year. The enhanced model can precisely
analyze and predict not only genetic mutations and expression
patterns but also detect subtle changes in human cells and tissues.
This advancement could enable earlier cancer detection, more
accurate disease progression forecasts, and support the development
of new drugs and personalized treatments.

A key breakthrough lies in the new technology that trains the AI
not just on small pathology image patches but also on whole-slide
imaging, pushing genetic mutation prediction accuracy to a
world-leading 78.4 percent.

LG AI Research expects this technology to secure the critical
“golden hour” for cancer patients by slashing gene test turnaround
times from over two weeks to under a minute. The institute also
introduced disease-specific AI models focused on lung and
colorectal cancers.

To strengthen this initiative, LG has partnered with Dr. Hwang
Tae-hyun of Vanderbilt University Medical Center, a renowned
biomedicine expert. Dr. Hwang, a prominent Korean scientist, leads
the U.S. government-supported “Cancer Moonshot” project aimed at
combating gastric cancer.

Together, LG AI Research and Dr. Hwang’s team plan to develop a
multimodal medical AI platform that integrates real clinical tissue
samples, pathology images, and treatment data from cancer patients
enrolled in clinical trials. They believe this collaboration will
usher in a new era of personalized, precision medicine.

This partnership also reflects Chairman Koo’s strategic push to
position AI and biotechnology as transformative technologies that
fundamentally improve people’s lives. LG AI Research and Dr.
Hwang’s team regard their platform as the world’s first attempt to
implement clinical AI at such a comprehensive level.

While oncology is the initial focus, the team plans to expand
the platform’s capabilities into other critical areas such as
transplant rejection, immunology, and diabetes research.

“Our goal isn’t just to develop another AI model,” Dr. Hwang
said. “We want to create a platform that genuinely assists doctors
in real clinical settings. This won’t be merely a diagnostic tool —
it has the potential to become a game changer that transforms the
entire process of drug development.”



Source link

Continue Reading

AI Research

Global CPG Companies Join Generative and Agentic AI Rush

Published

on

By


Consumer packaged goods companies are accelerating the adoption of artificial intelligence in their operations, marketing and supply chains as they seek new ways to boost growth and efficiency in a mature and competitive industry.

In May, PepsiCo announced a collaboration with Amazon Web Services to enhance its in-house generative AI platform, PepGenX. The partnership gives PepGenX access to various multimodal and agentic AI models on AWS.

“This strategic collaboration will strengthen our mature cloud strategy and unlock new levels of agility, intelligence and scalability across the company,” Athina Kanioura, chief strategy and transformation officer at PepsiCo, said in a statement.

The partnership spans PepsiCo’s lines of business globally. The changes include the following:

  • Moving applications and workloads to the cloud.
  • Giving in-house developers access to different multimodal AI models and agentic AI capabilities to enhance PepGenX, via AWS.
  • Enabling insights into real-time advertising performance, audience segmentation, hyper-personalized content and targeted marketing capabilities across Amazon’s customers.
  • Collaborating to transform digital supply chain capabilities, including predictive maintenance for manufacturing and logistics.

On the heels of this alliance, PepsiCo announced last month that it would deploy Salesforce’s Agentforce AI agents to manage “key functions,” enhance customer support and operational efficiency, and empower the sales team to focus on growth and deeper client engagement.

“Embracing an AI-first world means reimagining an enterprise where humans and intelligent agents don’t just coexist, they collaborate,” Kanioura said in a statement.

Humans and AI agents will be able to work together to respond faster to customer service inquiries, enable more targeted and automated marketing campaigns and promotions, and more.

In April, at Nvidia’s GTC conference, Pepsico showcased a digital twin of a warehouse using AI to simulate and optimize operations. The model incorporates generative AI and computer vision to test scenarios before deploying changes to physical facilities.

The June PYMNTS Intelligence report “AI at the Crossroads: Agentic Ambitions Meet Operational Realities” found that virtually every large organization is embracing generative AI to enhance productivity, streamline decision making and drive innovation. They are also using generative AI to improve the services and goods they offer to customers.

However, the next iteration — AI agents that autonomously perform tasks — is giving chief operating officers pause, according to the report. More than half of COOs are concerned about the accuracy of AI-generated outputs. Even narrow tasks like coding still require at least some human oversight.

See also: CPG Marketing Embraces New Business Models for Digital Transformation

Unilever, Nestlé and Coca-Cola Jump In

Unilever, the maker of Dove, Knorr, Ben & Jerry’s and more, has several AI initiatives. One of the more recent developments is the creation of digital twins of its products to add depth to their images, slated for ads.

Using Real-Time 3D, Nvidia Omniverse and OpenUSD, these 3D replicas add a “level of realism” the company has never achieved before, helping the products stand out in a sea of ads, Unilver said.

Unilever’s creative staff can also use a single product shot to change wording, languages, backgrounds, formats and other variants quickly for different channels such as TV, digital commerce and the like.

“Our product twins can be deployed everywhere and anywhere, accurately and consistently, so content is generated faster and on brand,” Unilever Chief Growth and Marketing Officer Esi Eggleston Bracey said in a statement. “We call it creativity at the speed of life.”

The use of digital twins not only cuts costs but enables Unilever to bring products to market faster, the company said.

For example, its beauty and wellbeing brands were the first to use digital twins, and the company is now expanding the tech to include TRESemmé, Dove, Vaseline and Clear.

Unilever said it is seeing 55% in savings and a 65% faster turnaround in content creation. These images also elicit higher engagement with customers, holding their attention three times longer than traditional images, and doubling their click-through rates.

In another use of AI, Unilever can gather insights across its global operations to do forecasting and inform channel strategy.

For example, advanced modeling powered by AI can help sales representatives predict what a retailer is likely to buy. As such, sales teams can now personalize their engagement strategies, customize their loyalty programs and plan more targeted promotions.

Using AI and image processing, photos of in-store displays become a key data source for sales teams. They can get insights into stock levels to better advise retailers on product placement and merchandising.

Other CPG firms are following suit. In June, Nestlé also launched digital twins of its products for marketing purposes. These 3D virtual replicas let creative teams revise product packaging, change backgrounds and make other changes to adapt to local markets.

“This means that new creative content can be generated using AI, without having to constantly reshoot from scratch,” according to a company blog post.

As such, Nestlé can respond quicker in a fast-moving digital environment where ad campaigns on social media often require six or more different ad formats to be successful and product packaging changes constantly.

The company worked with Accenture, Nvidia and Microsoft on the initiative.

This month, Nestlé said its R&D team is working with IBM to invent a new generative AI tool that can find new types of packaging materials. Nestlé said it is moving away from the use of virgin plastic toward alternative materials such as recyclable and paper-based packaging.

Nestlé wants to find packaging materials that not only protect its content but also are cost-effective and recyclable.

The Coca-Cola Company is also actively using AI. In May, the company announced a partnership with Adobe to embed AI in design at scale. Project Fizzion, a design intelligence system, learns from designers and encodes their creative intent to automatically apply brand rules across formats, platforms and markets.

This encoded intent, StyleID, acts as a real-time guide to Coca-Cola teams and creative partners to generate hundreds of localized ad campaign versions for faster execution.

However, Coca-Cola has had an early misstep in using AI. Last year, consumers criticized its AI-generated Christmas promotion video as “soulless” and “devoid of any actual creativity,” according to NBC News.

For all PYMNTS AI coverage, subscribe to the daily AI Newsletter.

Read more:



Source link

Continue Reading

Trending