File size: 1,525 Bytes
26fd6a5
 
 
 
 
 
9122576
26fd6a5
 
 
 
 
 
 
 
 
 
 
 
90deb69
 
26fd6a5
 
9122576
 
 
26fd6a5
f5310c4
 
 
 
d3100ed
 
 
f5310c4
5c612ca
f5310c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9122576
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
import gradio as gr
from dotenv import load_dotenv
import os
from openai import OpenAI
import spacy
import random

# Load environment variables from .env file
load_dotenv()

# Access the env
HF_TOKEN = os.getenv('HUGGING_FACE_TOKEN')

# openai setup
client = OpenAI(
  api_key=os.getenv('OPENAI_API_KEY')
)

# Global variable to control debug printing
DEBUG_MODE = True


def debug_print(*args, **kwargs):
    if DEBUG_MODE:
        print(*args, **kwargs)

def generate_questions(input_prompt):
    """
    Generates EFL questions based on the input text using OpenAI's GPT-3.
    """
   

    prompt=f"Generate 5 simple questions for an EFL (English as a Foreign Language) based on the following topic: {input_prompt}"

    response = client.chat.completions.create(

        messages=[
            {"role": "system", "content": ""},
            {"role": "user", "content": prompt}
        ],

        model="gpt-3.5-turbo",
      )
    questions = response.choices[0].message.content
    debug_print("GPT output:", questions)

    return questions

with gr.Blocks() as app:
    with gr.Column():
        gr.Markdown("### EFL Question Generator")
        input_text = gr.Textbox(label="Topic", lines=1, placeholder="Type or paste your topic here...", value="China")
        output_questions = gr.Textbox(label="Generated Questions", lines=5)
        generate_btn = gr.Button("Generate Questions")
        generate_btn.click(fn=generate_questions, inputs=input_text, outputs=output_questions)

app.launch()