File size: 7,017 Bytes
cb3c432
c43df60
0fda4e7
 
 
 
 
 
 
 
 
 
 
 
55219d1
0fda4e7
ed5b451
0fda4e7
 
 
 
 
 
 
 
 
 
 
ed5b451
 
 
 
 
 
c43df60
0fda4e7
 
ed5b451
0fda4e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed5b451
0fda4e7
 
 
 
 
ed5b451
0fda4e7
 
 
 
 
a30c9c8
ed5b451
 
0fda4e7
 
ed5b451
c43df60
ed5b451
a30c9c8
0fda4e7
 
 
ed5b451
0fda4e7
 
 
ed5b451
0fda4e7
 
ed5b451
0fda4e7
 
 
 
 
ed5b451
0fda4e7
 
ed5b451
0fda4e7
 
 
 
 
 
ed5b451
0fda4e7
 
 
 
 
ed5b451
0fda4e7
ed5b451
 
0fda4e7
 
ed5b451
 
 
 
0fda4e7
ed5b451
 
 
0fda4e7
ed5b451
0fda4e7
ed5b451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fda4e7
 
 
ed5b451
 
0fda4e7
c43df60
0fda4e7
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import os
import openai
import gradio as gr
from datetime import datetime

# ------------------------------------------------------------
# App Identity
# ------------------------------------------------------------
APP_TITLE = "Parampara & Prayog — Hindi Sahitya Adhyayan & Anusandhān Kendra"
APP_DESCRIPTION = (
    "A digital mentorship and research space inspired by the academic legacy "
    "of Presidency University’s Faculty of Arts — bringing together Parampara (Tradition) "
    "and Prayog (Experiment) in Hindi Studies."
)

# ------------------------------------------------------------
# OpenAI API Key Setup
# ------------------------------------------------------------
openai.api_key = os.getenv("OPENAI_API_KEY")

# ------------------------------------------------------------
# Professor Voice Prompt
# ------------------------------------------------------------
BASE_PROMPT = """
You are a senior Professor of Hindi Literature and former Dean of Arts at Presidency University, Kolkata.
You specialise in Modern & Contemporary Hindi Poetry, Comparative Literature, Religion & Society in Hindi Texts,
and literary research guidance.

Write in a calm, reflective, academic tone.
When you answer:
- Give conceptual explanations, not bullet points.
- Quote Hindi authors or critics where appropriate.
- Encourage comparative analysis.
- Use Devanagari for quotes and titles; English for explanation unless full Hindi mode is selected.
"""

# ------------------------------------------------------------
# Dropdown Options
# ------------------------------------------------------------
DOMAINS = [
    "Modern Hindi Poetry (आधुनिक हिंदी कविता)",
    "Contemporary Hindi Poetry (समकालीन कविता)",
    "Medieval Hindi Literature (मध्यकालीन हिंदी साहित्य)",
    "Modern Hindi Fiction & Prose (आधुनिक गद्य)",
    "Comparative Hindi Literature (तुलनात्मक साहित्य)",
    "Religion & Philosophy in Hindi Literature (धर्म और दर्शन)",
    "Research Methodology in Hindi Studies (अनुसंधान पद्धति)",
    "Translation Studies (अनुवाद अध्ययन)",
    "Dalit & Feminist Literature (दलित और नारीवादी साहित्य)",
    "Postmodern and Global Hindi (उत्तर आधुनिकता और वैश्विक हिंदी)",
]

AUDIENCES = [
    "Undergraduate Student",
    "Postgraduate Student",
    "PhD / Research Scholar",
    "Faculty / Teacher",
    "Independent Reader",
]

# ------------------------------------------------------------
# LLM Response
# ------------------------------------------------------------
def generate_response(domain, query, audience, language):
    lang_note = (
        "Respond in English with Devanagari quotes."
        if language == "English"
        else "Respond fully in Hindi (Devanagari)."
    )
    prompt = (
        f"{BASE_PROMPT}\n\nDomain: {domain}\nAudience: {audience}\n{lang_note}\n\n"
        f"Student Query:\n{query}\n\nAnswer:"
    )
    try:
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[{"role": "system", "content": prompt}],
            temperature=0.7,
            max_tokens=800,
        )
        return response["choices"][0]["message"]["content"]
    except Exception as e:
        return f"⚠️ Error fetching response: {e}"

# ------------------------------------------------------------
# Knowledge Base (Example Notes)
# ------------------------------------------------------------
KNOWLEDGE_BASE = {
    "Research Guidance": [
        "How to select a topic for Hindi PhD.",
        "Common pitfalls in literary analysis.",
        "Structuring dissertation chapters.",
        "Citation and referencing in Hindi research.",
    ],
    "Comparative Literature": [
        "Hindi–Bengali modernist influences.",
        "Urdu–Hindi poetic dialogue.",
        "Translation as interpretation.",
        "Cross-cultural motifs in Hindi fiction.",
    ],
    "Commentaries": [
        "Annotated readings of Agyeya, Nirala, and Muktibodh.",
        "Bhakti and Modernity: Kabir to Nagarjun.",
        "Gender in Hindi poetry: Mahadevi Verma and beyond.",
    ],
}

# ------------------------------------------------------------
# Interface Logic
# ------------------------------------------------------------
def mentorship_interface(domain, audience, query, language):
    return generate_response(domain, query, audience, language)

# ------------------------------------------------------------
# Gradio Interface
# ------------------------------------------------------------
with gr.Blocks(title=APP_TITLE) as demo:
    gr.Markdown(f"## 🌸 {APP_TITLE}")
    gr.Markdown(APP_DESCRIPTION)

    with gr.Tab("A. Study Modules & Guidance"):
        domain = gr.Dropdown(choices=DOMAINS, label="Select Literary Domain")
        audience = gr.Dropdown(choices=AUDIENCES, label="Audience Type")
        query = gr.Textbox(label="Enter your academic query", lines=4)
        language = gr.Radio(["English", "Hindi"], label="Response Language", value="English")
        output = gr.Textbox(label="Professor’s Response", lines=12)
        ask_btn = gr.Button("Ask for Guidance")
        ask_btn.click(mentorship_interface, [domain, audience, query, language], output)

    with gr.Tab("B. Research Mentorship"):
        gr.Markdown("💡 Detailed mentoring on research design and methodology:")
        for topic in KNOWLEDGE_BASE["Research Guidance"]:
            gr.Markdown(f"- {topic}")

    with gr.Tab("C. Comparative Literature Lab"):
        gr.Markdown("🔶 Intersections of Hindi with other literatures:")
        for topic in KNOWLEDGE_BASE["Comparative Literature"]:
            gr.Markdown(f"- {topic}")

    with gr.Tab("D. Annotated Texts & Commentaries"):
        gr.Markdown("📘 Selected commentaries and readings:")
        for topic in KNOWLEDGE_BASE["Commentaries"]:
            gr.Markdown(f"- {topic}")

    with gr.Tab("E. Recorded Intellectual Presence"):
        gr.Markdown("🎙️ Placeholder for lectures and reflections.")
        gr.Markdown("_Coming soon: Audio-visual archives of the Professor._")

    with gr.Tab("F. Ask the Professor"):
        gr.Markdown("✍️ Submit questions for asynchronous academic discussion.")
        question = gr.Textbox(label="Your Question", lines=3)
        reply = gr.Textbox(label="Response", lines=8)
        submit_btn = gr.Button("Submit Question")
        submit_btn.click(mentorship_interface, [domain, audience, question, language], reply)

    with gr.Tab("Audience & Contribution"):
        gr.Markdown(
            "👥 Former students and scholars may contribute annotated notes, "
            "comparative findings, and new research topics."
        )

demo.launch(server_name="0.0.0.0", server_port=7860, share=True)