How to present response containing code?

#3
by ttxy - opened

When I prompt with "show me a gradio example", the response in condensed into one line as

Sure! Here's an example of a simple Python code that generates a random number and asks the user to guess it. The code will keep prompting the user for guesses until they guess the correct number: python import random # Generate a random number between 1 and 100 num = random.randint(1, 100) # Keep prompting the user for guesses until they guess the correct number while True: guess = input("Guess a number between 1 and 100: ") try: guess = int(guess) if guess < 1 or guess > 100: print("Invalid input! Please enter a number between 1 and 100.") elif guess < num: print("Too low! Try again.") elif guess > num: print("Too high! Try again.") else: print("Congratulations! You guessed the correct number!") break except ValueError: print("Invalid input! Please enter a valid number.")This code makes use of the random module to generate a random integer between 1 and 100. The program will keep prompting the user for guesses until they get the right answer. The code also includes some basic input validation to ensure that the user enters a valid input.

How can I present the above response in a more readable way, such as:

Here is the code:

import gradio as gr 
import os 
print("hi")

I don't think it's possible atm with gradio. I guess one solution is to ask chatgpt to format code properly.

ttxy changed discussion status to closed

Sign up or log in to comment